|  | 
|  | 
| 
| Re: [JET] XPath query to select unique nodes [message #48973 is a reply to message #48943] | Mon, 25 August 2008 18:25  |  | 
| Eclipse User  |  |  |  |  | Originally posted by: mozafara.cs.man.ac.uk 
 Paul,
 I eventually used a very similar approach to yours, but had to copy the
 unique nodes (without children) under a new subtree for future
 reference. Before copying each node I checked if it already existed
 under the new tree.
 
 Paul Elder wrote:
 > Amin:
 >
 > Well, it is certainly possible that there is a defect in preceding-sibling -
 > can you post an example?
 >
 > But, more importantly, there was a comment on that linked page which caught
 > my eye: "this is O(N^2) and will be very slow for a large list..."
 >
 > So, I'd be looking for an alternative anyhow...
 >
 > With JET 0.9 (ganymede), there is a sort function that could be used to do a
 > directory like solution similar that described in this "What's new in XSLT
 > 2.0" article (http://www.xml.com/pub/a/2002/04/10/xslt2.html?page=2)
 >
 > Assuming a document like:
 >
 > <cities>
 >   <city name="milan"  country="italy"   pop="5"/>
 >   <city name="paris"  country="france"  pop="7"/>
 >   <city name="munich" country="germany" pop="4"/>
 >   <city name="lyon"   country="france"  pop="2"/>
 >   <city name="venice" country="italy"   pop="1"/>
 > </cities>You could write a template like this:
 >
 > <c:setVariable var="lastCountry" select=" 'NotACountry' "/>
 > <c:iterate select="sort(/cities/city, '@country')" var="city">
 >    <c:if test="not($lastCountry = $city/@country)">
 >        Country: <c:get select="$city/@country"/>
 >        <c:setVariable var="lastCountry" select=" $city/@country "/>
 >    </c:if>
 >           City: <c:get select="$city/@name"/>
 > </c:iterate>
 >
 > The sort uses the standard Java Collections.sort(), so the above approach is
 > at worst O(N-log(N)).
 >
 > Paul
 >
 >
 |  |  |  | 
Powered by 
FUDForum. Page generated in 0.03727 seconds