xsl-list
[Top] [All Lists]

Re: [xsl] Ranking Random Nodes from Top to Bottom

2007-08-17 05:13:04
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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--