|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Sort question
Thanks for your help and I understand what your getting at, but what if the
XML wasn`t quite so simple, ie:
<CRUMBTRAILS> <CRUMBTRAIL> <ANCESTOR> <NODEID>889</NODEID> <NAME>Top</NAME> <TREELEVEL>0</TREELEVEL> </ANCESTOR> <ANCESTOR> <NODEID>72</NODEID> <NAME>Life</NAME> <TREELEVEL>1</TREELEVEL> </ANCESTOR> <ANCESTOR> <NODEID>21</NODEID> <NAME>Families</NAME> <TREELEVEL>2</TREELEVEL> </ANCESTOR> </CRUMBTRAIL> <CRUMBTRAIL> <ANCESTOR> <NODEID>889</NODEID> <NAME>Top</NAME> <TREELEVEL>0</TREELEVEL> </ANCESTOR> <ANCESTOR> <NODEID>73</NODEID> <NAME>Hobbies</NAME> <TREELEVEL>1</TREELEVEL> </ANCESTOR> <ANCESTOR> <NODEID>83</NODEID> <NAME>Travel & Transport</NAME> <TREELEVEL>2</TREELEVEL> </ANCESTOR> <ANCESTOR> <NODEID>52</NODEID> <NAME>Transport</NAME> <TREELEVEL>3</TREELEVEL> </ANCESTOR> </CRUMBTRAIL> <CRUMBTRAIL> <ANCESTOR> <NODEID>889</NODEID> <NAME>Top</NAME> <TREELEVEL>0</TREELEVEL> </ANCESTOR> <ANCESTOR> <NODEID>72</NODEID> <NAME>Life</NAME> <TREELEVEL>1</TREELEVEL> </ANCESTOR> <ANCESTOR> <NODEID>117</NODEID> <NAME>Toys, Games & Hobbies</NAME> <TREELEVEL>2</TREELEVEL> </ANCESTOR> <ANCESTOR> <NODEID>797</NODEID> <NAME>Toys</NAME> <TREELEVEL>3</TREELEVEL> </ANCESTOR> </CRUMBTRAIL> <CRUMBTRAIL> <ANCESTOR> <NODEID>889</NODEID> <NAME>Top</NAME> <TREELEVEL>0</TREELEVEL> </ANCESTOR> <ANCESTOR> <NODEID>72</NODEID> <NAME>Life</NAME> <TREELEVEL>1</TREELEVEL> </ANCESTOR> <ANCESTOR> <NODEID>117</NODEID> <NAME>Toys, Games & Hobbies</NAME> <TREELEVEL>2</TREELEVEL> </ANCESTOR> <ANCESTOR> <NODEID>798</NODEID> <NAME>Games</NAME> <TREELEVEL>3</TREELEVEL> </ANCESTOR> </CRUMBTRAIL> <CRUMBTRAIL> <ANCESTOR> <NODEID>889</NODEID> <NAME>Top</NAME> <TREELEVEL>0</TREELEVEL> </ANCESTOR> <ANCESTOR> <NODEID>72</NODEID> <NAME>Life</NAME> <TREELEVEL>1</TREELEVEL> </ANCESTOR> <ANCESTOR> <NODEID>117</NODEID> <NAME>Toys, Games & Hobbies</NAME> <TREELEVEL>2</TREELEVEL> </ANCESTOR> <ANCESTOR> <NODEID>800</NODEID> <NAME>Computer Games</NAME> <TREELEVEL>3</TREELEVEL> </ANCESTOR> </CRUMBTRAIL> </CRUMBTRAILS> With this I need to sort, in the same way only with <NAME> as my sort key. (Using your previous methodology it appears the NODEID and TREELEVEL is getting in the way with this tree)
For your type of xml source document, yes, it is possible. The following transformation: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes"/> <xsl:variable name="vWhite" select="' '"/> <xsl:variable name="vLowest" select="'			'"/> <xsl:template match="/">
<sorted>
<xsl:for-each select="/*/crumbtrail">
<xsl:sort select="translate(., $vWhite, $vLowest)"/> <xsl:copy-of select="."/>
</xsl:for-each>
</sorted>
</xsl:template>
</xsl:stylesheet>when applied on this source.xml: <root> <crumbtrail> <crumb>top</crumb> <crumb>sport</crumb> <crumb>football</crumb> <crumb>liverpool</crumb> </crumbtrail> <crumbtrail> <crumb>top3</crumb> <crumb>spo</crumb> <crumb>foot</crumb> <crumb>liverpool</crumb> </crumbtrail> <crumbtrail> <crumb>top</crumb> <crumb>sport</crumb> </crumbtrail> <crumbtrail> <crumb>top2</crumb> <crumb>sportX</crumb> </crumbtrail> <crumbtrail> <crumb>top2</crumb> <crumb>spo</crumb> </crumbtrail> <crumbtrail> <crumb>top</crumb> <crumb>sport</crumb> <crumb>cricket</crumb> </crumbtrail> </root> produces this result: <sorted><crumbtrail> <crumb>top</crumb> <crumb>sport</crumb> </crumbtrail><crumbtrail> <crumb>top</crumb> <crumb>sport</crumb> <crumb>cricket</crumb> </crumbtrail><crumbtrail> <crumb>top</crumb> <crumb>sport</crumb> <crumb>football</crumb> <crumb>liverpool</crumb> </crumbtrail><crumbtrail> <crumb>top2</crumb> <crumb>spo</crumb> </crumbtrail><crumbtrail> <crumb>top2</crumb> <crumb>sportX</crumb> </crumbtrail><crumbtrail> <crumb>top3</crumb> <crumb>spo</crumb> <crumb>foot</crumb> <crumb>liverpool</crumb> </crumbtrail></sorted>
1. Whitespace nodes in the xml source must be preseved. 2. The "lowest character" for the given XSLT processor must be known in advance, so that it can be used as the intended result of translating the white-space. 3. The text-nodes children of crumb may contain only one (and the same) type of whitespace character (e.g. only blanks are allowed). Note that because the implementation of xsl:sort differs on different XSLT processors (or even between different versions of the same XSLT procesor -- e.g. Xalan-J and Xalan-C), different results may be produced if the xsl:variable "vLowest" is not set appropriately. The above result is produced by: MSXML3/4, MS .Net xslTransform, Saxon 6.5.2, XalanC 1.3. In order for XalanJ 2.4.1 to produce the same results the following should be specified: <xsl:variable name="vLowest" select="000"/>
Dimitre Novatchev. http://fxsl.sourceforge.net/ -- the home of FXSL _________________________________________________________________ Stay in touch with MSN Messenger http://messenger.msn.co.uk 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
|

Cart








