I would like to have a list sorted ignoring any initial definite/indefinite articles \'the\' and \'a\'. For instance:
This transformation:
<xsl:template match="plays">
<p>Plays sorted by title: </p>
<xsl:for-each select="play">
<xsl:sort select=
"concat(@title
[not(starts-with(.,'A ')
or
starts-with(.,'The '))],
substring-after(@title[starts-with(., 'The ')], 'The '),
substring-after(@title[starts-with(., 'A ')], 'A ')
)
"/>
<p>
<xsl:value-of select="@title"/>
</p>
</xsl:for-each>
</xsl:template>
when applied on this XML document:
produces the wanted, correct result:
<p>Plays sorted by title: </p>
<p>Barber</p>
<p>The Comedy of Errors</p>
<p>CTA & Fred</p>
<p>Hamlet</p>
<p>A Midsummer Night's Dream</p>
<p>Twelfth Night</p>
<p>The Winter's Tale</p>
Here is how I would do that:
<xsl:template match="plays">
<xsl:for-each select="play">
<xsl:sort select="substring(title, 1 + 2*starts-with(title, 'A ') + 4*starts-with(title, 'The '))"/>
<p>
<xsl:value-of select="title"/>
</p>
</xsl:for-each>
</xsl:template>
Update: I forgot to add 1 to the expression (classic off-by-one error)
Well, starts-with
is from XSLT 1.0. Prooflink: the first search result in Google yields XSLT 1.0: function starts-with