开发者

sorting by first letter [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Ignoring 'A' and 'The' when sorting with XSLT

I have a list of places, however som开发者_Go百科e of theses places have the word 'the' in front. I need help in sorting these places in alphabetical order by discarding the 'the'. eg the mountains, should be just mountains. i can strip out the word 'the' to display the name by using substring however the sort doesn't seem to be able to read this.

I have this so far.

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

example of what comes back:

alpha

sigma

the beta

would like it to come back with:

alpha

beta

sigma

this is just an example of how i stripped it from the name:

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


Use:

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

Note: You could also use translate() function for case-insensitivity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜