Ignoring 'A' and 'The' when sorting with XSLT
Posted
by ChrisV
on Stack Overflow
See other posts from Stack Overflow
or by ChrisV
Published on 2010-05-17T11:35:38Z
Indexed on
2010/05/17
11:40 UTC
Read the original article
Hit count: 618
I would like to have a list sorted ignoring any initial definite/indefinite articles 'the' and 'a'. For instance:
- The Comedy of Errors
- Hamlet
- A Midsummer Night's Dream
- Twelfth Night
- The Winter's Tale
I think perhaps in XSLT 2.0 this could be achieved along the lines of:
<xsl:template match="/">
<xsl:for-each select="play"/>
<xsl:sort select="if (starts-with(title, 'A ')) then substring(title, 2) else
if (starts-with(title, 'The ')) then substring(title, 4) else title"/>
<p><xsl:value-of select="title"/></p>
</xsl:for-each>
</xsl:template>
However, I want to use in-browser processing, so have to use XSLT 1.0. Is there any way to achieve this in XLST 1.0?
© Stack Overflow or respective owner