当前位置: 动力学知识库 > 问答 > 编程问答 >

xml - how to change the natural sort order in XSLT

问题描述:

I have been using <xsl:sort select="."/> method to sort some values, Can i force the sort method to follow order as,

 i) sort numbers first

ii) next greek symbols

iii) and next english alphabets

What i get as output is,

 i) numbers

ii) alphabets

iii) greek symbols

网友答案:

You could use three xsl:sort where the first tries to remove anything but digits e.g.

<xsl:sort select="xs:integer(replace(., '[^0-9]+', ''))"/>

then add a second sort

<xsl:sort select="replace(., '[^0-9a-z]+', '', 'i')"/>

to sort on the remaining Greek characters and lastly do

<xsl:sort select="replace(., '[^a-z]+', '', 'i')"/>

to sort on the English letters. If needed the regular expression would also allow you to define the range of Greek letters but I don't know there unicode numbers so if you need that you can look it up at unicode.org.

分享给朋友:
您可能感兴趣的文章:
随机阅读: