[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Sorting upper and lower case separately.
>Is there any way to cause the sort command to sort all the upper case = >first and then the lower case? I don't mean using the upper-case or = >lower-case settings, because that just determines which order they are = >in. But I want the following results: This should work, although to me it looks a bit long-winded. So, to sort this xml by case (upperfirst) and then by value: <root> <node>apple</node> <node>Orange</node> <node>bannana</node> <node>Pear</node> <node>peach</node> <node>Monkey</node> </root> Output required: Monkey Orange Pear apple bannana peach The XSL: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'"/> <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/> <xsl:variable name="hashes" select="'##########################'"/> <xsl:variable name="lowercasenodes" select="root/node[starts-with(translate(.,$lowercase,$hashes),'#')]"/> <xsl:variable name="uppercasenodes" select="root/node[starts-with(translate(.,$uppercase,$hashes),'#')]"/> <xsl:template match="/"> <xsl:apply-templates select="root/node" mode="upper"> <xsl:sort select="."/> </xsl:apply-templates> <xsl:apply-templates select="root/node" mode="lower"> <xsl:sort select="."/> </xsl:apply-templates> </xsl:template> <xsl:template match="node" mode="lower"> <xsl:if test=". = $lowercasenodes"> <xsl:value-of select="."/><br/> </xsl:if> </xsl:template> <xsl:template match="node" mode="upper"> <xsl:if test=". = $uppercasenodes"> <xsl:value-of select="."/><br/> </xsl:if> </xsl:template> </xsl:stylesheet> cheers andrew === XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|