[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Ranking Random Nodes from Top to Bottom

Subject: Re: Ranking Random Nodes from Top to Bottom
From: "J. Zhang" <j.zhang@xxxxxx>
Date: Fri, 17 Aug 2007 14:12:34 +0200
Re:  Ranking Random Nodes from Top to Bottom
Hi Abel,

Abel Braaksma wrote:
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]?

You are right. :)


I will try out your solution.

Thanks!
  jz
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), '&#xA;')">
    <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), '&#xA;')">
<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), '&#xA;')">
<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,

I got a long list of absolute xpath paths in a flat file, like

/root[1]/node[2]/node[12]/node[1]
/root[1]/node[1]
/root[1]/node[2]/node[12]/node[1]
/root[1]/node[4]/node[12]
/root[1]

Is there an existing function in Saxon or ready-made code to rank the list of nodes from top to bottom?

Thanks by advance!
  jz

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.