[xsl] Re: query

Subject: [xsl] Re: query
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Sat, 8 Mar 2003 11:32:16 +0100
> I'm looking for an xpath query to get me the template node with the
largest
> version number from the largest subset of templates with the same id.
>
> The XML looks like:
>
> <Template id="1" version="0"/>
> <Template id="2" version="0"/>
> <Template id="3" version="0"/>
> <Template id="2" version="1"/>
>
> In the above XML, the answer to my query would be <Template id="2"
> version="1"/>

0. I added a top element to the source.xml above, to make it well-formed xml
document.

1. I understand this as a request to specify a *single* XPath expression
that returns the node with the specified properties.

2. I assume also, that the values of the "version" attributes of "Template"
elements having different id-s are independent from each other and are
increasing uniformly  from

    0
to
    count(/*/Template[@id = $thisId]) - 1

If these assumptions are correct, then the largest "version" for the largest
subset of "Template" elements with the same "id" -- this will be the maximum
for the values of the "version" attributes of the whole document above.


*In this case* the single XPath expression that returns the "Template"
element "with the largest version number from the largest subset of
templates with the same id" is:

   /*/*[not(@version < /*/*/@version)]

(One has to escape the "<" above in case this XPath expression has to be
specified as value of an attribute within an XML document)


In case the assumptions 1. and 2. do not hold, then there's no single XPath
1.0 expression that returns the wanted result -- the reason is that in XPath
1.0 it is not possible to have variable definitions as part of an
expression.



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL







 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread