Subject: [xsl] Re: Sort question From: "Tom Whitehouse" <whitehousetom@xxxxxxxxxxx> Date: Fri, 28 Feb 2003 14:15:59 +0000 |
<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>
Date: Thu, 27 Feb 2003 21:30:30 +0100 From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx> Subject: [xsl] Re: Sort question
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<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>
<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>
<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>
Of course, this is quite special case. In order for this to work two things must be assured:
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:
These limitations can be avoided if a generic-template/functional sort implementation is used (or I guess in XSLT2 too).
===== Cheers,
Dimitre Novatchev. http://fxsl.sourceforge.net/ -- the home of FXSL
_________________________________________________________________ Stay in touch with MSN Messenger http://messenger.msn.co.uk
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Why oh Why?? Namespace ge, Dan Vint | Thread | [xsl] Stylesheet to remove comments, Scott Moore |
Re: Re[2]: [xsl] not standart table, Kevin Jones | Date | Re: [xsl] Is there any way to make , TP |
Month |