使用XSLT排序时忽略'A'和'The'

Chr*_*isV 3 sorting xslt xslt-1.0

我希望列出一个列表,忽略任何初始明确/不定的文章'the'和'a'.例如:

  • 错误的喜剧
  • 村庄
  • 仲夏夜之梦
  • 第十二夜
  • 冬天的故事

我想也许在XSLT 2.0中,这可以通过以下方式实现:

<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>
Run Code Online (Sandbox Code Playgroud)

但是,我想使用浏览器内处理,因此必须使用XSLT 1.0.有没有办法在XLST 1.0中实现这一目标?

Dim*_*hev 5

这种转变:

<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>
Run Code Online (Sandbox Code Playgroud)

应用于此XML文档时:

产生想要的,正确的结果:

<p>Plays sorted by title: </p>
<p>Barber</p>
<p>The Comedy of Errors</p>
<p>CTA &amp; Fred</p>
<p>Hamlet</p>
<p>A Midsummer Night's Dream</p>
<p>Twelfth Night</p>
<p>The Winter's Tale</p>
Run Code Online (Sandbox Code Playgroud)