2011-04-07 56 views
1

可能重复:
Ignoring 'A' and 'The' when sorting with XSLT排序按首字母

我的地点清单,但一些论文地方有“的”前面的词。我需要通过丢弃'the'来按字母顺序排序这些地方。如山,应该只是山。我可以通过使用子字符串去掉'the'这个词来显示这个名字,但是这个排序似乎不能读取这个。

我有这个到目前为止。什么回来

<xsl:sort data-type="text" order="ascending" select="@places" /> 

例如:

阿尔法
西格玛
公测

想它带回来:

阿尔法
测试
西格玛

这只是我如何去除它起名字的例子:

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

回答

1

用途:

<xsl:sort select="substring(@places, 5 * starts-with(@places,'the ')" /> 

注意:您也可以使用translate()功能不区分大小写。

+0

感谢您的快速回复,但它似乎并没有工作....我试过它仍然保持相同的顺序,就好像'The'仍然在那里.translate将从名称的其余部分删除所有的t,h和e 。道歉...即时通讯不是最好的在这 – Hatzi 2011-04-08 09:17:44

+0

我似乎已经得到它使用...感谢你的帮助 – Hatzi 2011-04-08 09:44:40

+0

@Hatzi:这个'substring(@places,5)* starts-with(@places,'The')'**不是我写的**。 'substring-after()'解决方案并不完全正确:子字符串可能在任何地方,而不是在第一个位置。 – 2011-04-08 12:36:26