2016-11-08 10 views
1

XMLファイルは、次のように与えられているのHTMLにXSL変換をXMLにソートし、私は、HTMLフォームにそれらをtranferしたい:どのよう

<?xml version="1.0" encoding="UTF-8"?> 
<bncDoc> 
<stext> 
<div> 
<u who="PS6H7"> 
<s n="3"> 
    <w c5="AV0" hw="well" pos="ADV">Has</w> 
    <c c5="PUN">, </c> 
    <w c5="AJ0" hw="good" pos="ADJ">Well </w> 
    <w c5="NN1" hw="afternoon" pos="SUBST">afternoon</w> 
    <c c5="PUN">, </c> 
    <w c5="PNI" hw="everybody" pos="PRON">everybody</w> 
    <c c5="PUN">, </c> 
    <w c5="PNP" hw="i" pos="PRON">I </w> 
    <w c5="VVB" hw="think" pos="VERB">think </w> 
    <w c5="PNP" hw="we" pos="PRON">we</w> 
    <w c5="VHD" hw="have" pos="VERB">'d </w> 
    <w c5="AV0" hw="well" pos="ADV">better </w> 
    <w c5="VVI" hw="get" pos="VERB">get </w> 
    <w c5="VVN" hw="start" pos="VERB">started</w> 
    <c c5="PUN">.</c> 
</s> 
</u> 

<u who="asdfgg"> 
<s n="4"> 
    <w c5="PNP" hw="we" pos="PRON">has </w> 
    <w c5="VVD" hw="look" pos="VERB">Well </w> 
    <w c5="AV0" hw="so" pos="ADV">so </w> 
    <w c5="AJ0" hw="thin" pos="ADJ">thin </w> 
    <w c5="PRP" hw="on" pos="PREP">on </w> 
    <w c5="AT0" hw="the" pos="ART">the </w> 
    <w c5="NN1" hw="ground" pos="SUBST">ground</w> 
    <c c5="PUN">, </c> 
    <w c5="PNP" hw="i" pos="PRON">I </w> 
    <w c5="VVD" hw="think" pos="VERB">thought </w> 
    <w c5="PNP" hw="we" pos="PRON">we</w> 
    <w c5="VM0" hw="would" pos="VERB">'d </w> 
    <w c5="VVI" hw="sit" pos="VERB">sit </w> 
    <w c5="CJC" hw="and" pos="CONJ">and </w> 
    <w c5="VVI" hw="wait" pos="VERB">wait </w> 
    <w c5="CJC" hw="and" pos="CONJ">and </w> 
    <w c5="VVI" hw="see" pos="VERB">see </w> 
    <w c5="CJS" hw="if" pos="CONJ">if </w> 
    <w c5="PNI" hw="everyone" pos="PRON">everyone</w> 
    <w c5="VBZ" hw="be" pos="VERB">'s </w> 
    <w c5="VVG-AJ0" hw="come" pos="VERB">coming</w> 
    <c c5="PUN">, </c> 
    <w c5="CJC" hw="but" pos="CONJ">but </w> 
    <w c5="UNC" hw="erm" pos="UNC">erm </w> 
    <w c5="PNP" hw="we" pos="PRON">we</w> 
    <w c5="VM0" hw="will" pos="VERB">'ll </w> 
    <w c5="VHI" hw="have" pos="VERB">have </w> 
    <w c5="TO0" hw="to" pos="PREP">to </w> 
    <w c5="VVI" hw="get" pos="VERB">get </w> 
    <w c5="VVN" hw="start" pos="VERB">started </w> 
    <w c5="AV0" hw="anyway" pos="ADV">anyway</w> 
    <c c5="PUN">.</c> 
</s> 
</u> 
</div> 
</stext> 
</bncDoc> 

と私はこのようなXSLドキュメントを終了しました:

<?xml version="1.0" encoding="ISO-8859-1"?> 
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <xsl:template match="bncDoc/stext/div/u/*/w"> 
     <xsl:for-each select="."> 
      <xsl:variable name="selectedWord" ><xsl:value-of select="."/></xsl:variable> 
      <xsl:variable name="countNumber" select="count(//w[contains(., $selectedWord)]) "/> 
      <tr> 
       <td id="row1"> 
        <xsl:value-of select="."/> 
       </td> 
       <td id="row2"> 
        <xsl:element name="number"> <xsl:value-of select="$countNumber"/></xsl:element> 
       </td> 
      </tr> 

     </xsl:for-each> 
    </xsl:template> 

    <xsl:template match="/"> 
     <html> 
      <body> 
       <h2>Frequency Table</h2> 
       <table border="1"> 
        <tr bgcolor="#CCCCCC"> 
         <th>Word</th> 
         <th>Show up Times</th> 
        </tr> 
        <xsl:apply-templates select="bncDoc/stext/div/u/*/w"></xsl:apply-templates> 
       </table> 
      </body> 
     </html> 
    </xsl:template> 

</xsl:stylesheet> 

出てきた結果は次のとおりです。 enter image description here

私は「タイムズアップ表示」行に基づいて結果をソートしたいが、それは動作していないようだ、と任意のソリューションがあります この問題を解決します?

+1

あなたの ''は完全に役に立たないです。結果を変更せずに削除することができます。 – Tomalak

+0

単純なソートの例をここで見ることができます - http://www.xml.com/pub/a/2002/07/03/transform.html – Rao

答えて

0

は、私はあなただけ出力ツリーに存在する何かでソートすることはできません「タイムズアップ表示」行

に基づいて結果をソートします。あなたは、ソートの目的で、カウントを繰り返す必要があります:

<xsl:apply-templates select="bncDoc/stext/div/u/*/w"></xsl:apply-templates> 

へ:

<xsl:apply-templates select="bncDoc/stext/div/u/*/w"> 
    <xsl:sort select="count(//w[contains(., current())])" data-type="number" order="descending"/> 
</xsl:apply-templates> 

P.S.これを変更しますあなたが実際にここでやりたいことは、というグループのグループです。http://www.jenitennison.com/xslt/grouping/muenchian.html