[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Ranking Random Nodes from Top to Bottom
I wonder what you mean by "ranking". Do you mean sorting? And what are
the rules for your sorting? Must node[1] come before node[2], and, more
importantly, must node[9] come before node[10]?
If it is just ordering, you can do it by using xsl:for-each or apply-templates with xsl:sort. If you don't know how to read the flat file, then lookup the documentation on the unparsed-text() function. If you don't know how to split the text, try to use tokenize().... All in all, something along these lines is probably what your code could look like eventually: <xsl:for-each select="tokenize(unparsed-text(yourfile.txt), '
')"> <xsl:sort /> </xsl:for-each> If numbers are of a concern to you and when they must be sorted numerically, it is a bit harder. With a known maximum depth you can do this: <xsl:for-each select="tokenize(unparsed-text(yourfile.txt), '
')"> <xsl:sort select="tokenize(., '/|\[')[1]" /> <xsl:sort select="tokenize(tokenize(., '/')[2], '\[|\]')[2]" data-type="number /> <xsl:sort select="tokenize(., '/|\[')[3]" /> <xsl:sort .... etc </xsl:for-each> but that would look rather ugly when you have more and more keys. In addition something like this is also possible: <xsl:for-each select="tokenize(unparsed-text(yourfile.txt), '
')"> <xsl:sort select="string-join(for $i in tokenize(a, '/\[\]') return if ($i castable as xs:integer) then (for $j in 0 to 5-string-length($i) return '0'), $i else $i, '')" /> </xsl:for-each> but, then again, that all depends on what you mean with "ranking". (none of the above tested). Btw, considering the very specific nature of the data, there's no existing function to do something like that. But you can achieve a lot with using xsl:sort. Cheers, -- Abel J. Zhang wrote: Hi all,
|
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
|