0
問題是,在下面的XSLT文檔中,我所有的hrow標籤都位於底部,我希望它保持它們出現的順序,我該怎麼做?XSLT在格式化xml文檔時維護標籤順序
我的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>
的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>
+1好答案。如果需要進行推式處理,也可以選擇'select ='row'hrow'。 – 2010-12-06 14:32:40