xml - XSLT how to sort by variable derived from original field? -
i'm new xslt, , wondering how sort based on derived variable such following (using 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 attempt:
<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>
desired output:
#1: first guy #2: second guy #3: third guy
thanks in advance help! chad
simpler:
<xsl:sort select="substring(substring-before(title, ':'), 2)" data-type="number" order="ascending" />
Comments
Post a Comment