我对 xslt 很陌生,想知道如何根据如下派生变量进行排序(使用 xslt 1.0):
xml:
<channel>
<item>
<title>#2: Second Guy</title>
</item>
<item>
<title>#3: Third Guy</title>
</item>
<item>
<title>#1: First Guy</title>
</item>
</channel>
xslt 尝试:
<xsl:for-each select="channel/item" >
<xsl:sort select="$rank" data-type="number" order="ascending" />
<xsl:variable name="rankStartPosn" select="string-length(substring-before(title, '#'))+1"/>
<xsl:variable name="rankEndPosn" select="string-length(substring-before(title, ':'))+1"/>
<xsl:variable name="rank" select="substring(title,number($rankStartPosn), number($rankEndPosn)-number($rankStartPosn))"/>
<p class="Normal">
<xsl:value-of select="title" />
</p>
</xsl:if>
</xsl:if>
</xsl:for-each>
期望的输出:
#1: First Guy
#2: Second Guy
#3: Third Guy
提前感谢您的帮助!乍得