2010-12-06 5 views
0

問題は、下のXSLT文書で、すべてのHrowタグが下部にあり、表示順序を維持したいのですが、どうすればいいですか?単に行うXSLTはXML文書の書式設定時にタグの順序を維持します

<log> 
<hrow time="45:43:2343">A heading</hrow> 
<row type="e">An error</row> 
<row type="w">An warn</row> 
<row type="i">An info</row> 
<row type="d">An debug</row> 
<row type="t">unknown</row> 
<hrow time="45:43:2343">Another heading</hrow> 
<row type="t">more rows</row> 
</log> 

ポストされたXML文書とXSLTドキュメント

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="/"> 
     <table width="100%"> 
      <xsl:apply-templates /> 
     </table> 
    </xsl:template> 

    <xsl:template match="log"> 
      <xsl:apply-templates select="row" /> 
      <xsl:apply-templates select="hrow" /> 
    </xsl:template> 

    <xsl:template match="row"> 
     <xsl:variable name="type" select="@type" /> 
     <xsl:choose> 
      <xsl:when test="$type = 'd'"> 
       <tr> 
        <td style="background-color:#C6F98B"> 
         <xsl:value-of select="." /> 
        </td> 
       </tr> 
      </xsl:when> 
      <xsl:when test="$type = 'i'"> 
       <tr> 
        <td style="background-color:#8B8BF9"> 
         <xsl:value-of select="." /> 
        </td> 
       </tr> 
      </xsl:when> 
      <xsl:when test="$type = 'e'"> 
       <tr> 
        <td style="background-color:#F9555D"> 
         <xsl:value-of select="." /> 
        </td> 
       </tr> 
      </xsl:when> 
      <xsl:when test="$type = 'w'"> 
       <tr> 
        <td style="background-color:#F8F781"> 
         <xsl:value-of select="." /> 
        </td> 
       </tr> 
      </xsl:when> 
      <xsl:otherwise> 
       <tr> 
        <td style="background-color:#E4E4E4"> 
         <xsl:value-of select="." /> 
        </td> 
       </tr> 
      </xsl:otherwise> 
     </xsl:choose> 
    </xsl:template> 

    <xsl:template match="hrow"> 
     <tr> 
      <td style="background-color:#DBC5FF;font-size: 16px;"> 
       <xsl:value-of select="." /> 
       [ 
       <xsl:value-of select="@time" /> 
       ] 
      </td> 
     </tr> 
    </xsl:template> 

</xsl:stylesheet> 

答えて

2

、代わりの

<xsl:template match="log"> 
     <xsl:apply-templates select="row" /> 
     <xsl:apply-templates select="hrow" /> 
</xsl:template> 

私のXML文書

<xsl:template match="log"> 
     <xsl:apply-templates/> 
</xsl:template> 

は、ドキュメントの順序でログ要素のすべての子ノードを処理します。あなたが他の子ノードを持っている場合

は、OR示されていないが、あなたは、プロセス

<xsl:template match="log"> 
     <xsl:apply-templates select="row | hrow"/> 
</xsl:template> 

選択された要素(すなわち行とHROWが)あまりにもドキュメント順に処理される方法を使用したくありません。

+0

+1良い答えです。また、プッシュスタイルの処理が必要な場合は、 'select =" row | hrow "を実行します。 –

関連する問題