我需要根据多个不同的节点对XML文件中的标记进行排序。例如:考虑以下XML:
<root>
<a>
<b>12</b>
<e>hello</e>
</a>
<a>
<b>11</b>
<e>how</e>
</a>
<a>
<c>13</c>
<f>are</f>
</a>
<a>
<b>21</b>
<f>you</f>
</a>
<a>
<d>22</d>
<e>hello</e>
</a>
<a>
<c>14</c>
<f>hi</f>
</a>
</root>
现在我需要从a
内的所有节点中找出最大数目。我试着这样做:
<xsl:template match="root">
<xsl:for-each select="a">
<xsl:sort select="b | c | d" data-type="number" order="descending"/> <!-- this gives me error-->
<xsl:if test="position() = 1">
<!-- how to access my node -->
</xsl:if>
</xsl:for-each>
</xsl:template>
如何进行排序并在排序后从第一个节点获得值?
提前感谢!!
注意:我用XSLT 1.0。
这个样式表:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="root">
<xsl:for-each select="a/*[string(number(.))!='NaN']">
<xsl:sort select="." order="descending"/>
<xsl:if test="position() = 1">
<highest><xsl:copy-of select="."/></highest>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
应用于上面编辑过的输入XML时,输出
<highest>
<d>22</d>
</highest>