使用XSLT实现排序的最佳方式是什么?
输入:<cross-refs>5,8,4,3,9</cross-refs>
除外输出:<cross-refs>3,4,5,8,9</cross-refs>
Thanks in advance
尝试:
<xsl:template match="cross-refs">
<xsl:copy>
<xsl:value-of separator=",">
<xsl:perform-sort select="tokenize(., ',')">
<xsl:sort select="." data-type="number"/>
</xsl:perform-sort>
</xsl:value-of>
</xsl:copy>
</xsl:template>
请注意,这假定您希望按数字顺序排序,而不是按字母顺序排序。
在XSLT 3.0中,您可以将其简化为:
<xsl:template match="cross-refs">
<xsl:copy>
<xsl:value-of select="sort(tokenize(., ',')!xs:integer(.))" separator=","/>
</xsl:copy>
</xsl:template>