Possible Duplicate:
Ignoring 'A' and 'The' when sorting with XSLT
I have a list of places, however som开发者_Go百科e of theses places have the word 'the' in front. I need help in sorting these places in alphabetical order by discarding the 'the'. eg the mountains, should be just mountains. i can strip out the word 'the' to display the name by using substring however the sort doesn't seem to be able to read this.
I have this so far.
<xsl:sort data-type="text" order="ascending" select="@places" />
example of what comes back:
alpha
sigma the betawould like it to come back with:
alpha
beta sigmathis is just an example of how i stripped it from the name:
<xsl:choose>
<xsl:when test="substring((@places), 0, 4) = 'The'">
<xsl:value-of select="substring(
(@places),
4,
string-length(@places)
)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@places" />
</xsl:otherwise>
</xsl:choose>
Use:
<xsl:sort select="substring(@places, 5 * starts-with(@places,'the ')" />
Note: You could also use translate()
function for case-insensitivity.
精彩评论