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,
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