gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 10:14:03 25 4
gpt4 key购买 nike

我想要一个忽略任何初始定冠词/不定冠词“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>

但是,我想使用浏览器内处理,所以必须使用 XSLT 1.0。有什么方法可以在 XLST 1.0 中实现这一点?

最佳答案

这个转换:

<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>

应用于此 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>

关于sorting - 使用 XSLT 排序时忽略 'A' 和 'The',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2848641/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com