Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [JET] XPath query to select unique nodes
[JET] XPath query to select unique nodes [message #48642] Thu, 14 August 2008 23:02 Go to next message
Eclipse User
Originally posted by: mozafara.cs.man.ac.uk

Is there a way to select a set of unique nodes in jet? I came over a
special XPath expression using preceding-sibling axis
( http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=253935 5&SiteID=1)
but this is not implemented in JET .8 in europa and JET .9 ganymede
seems to ignore it.

What is your best suggestion?
Thank you
Re: [JET] XPath query to select unique nodes [message #48943 is a reply to message #48642] Mon, 25 August 2008 20:18 Go to previous messageGo to next message
Paul Elder is currently offline Paul Elder
Messages: 849
Registered: July 2009
Senior Member
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
Re: [JET] XPath query to select unique nodes [message #48973 is a reply to message #48943] Mon, 25 August 2008 22:25 Go to previous message
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
>
>
Previous Topic:RSS Feed error
Next Topic:"Successfull Execution" logged in the Error log after a transformation
Goto Forum:
  


Current Time: Tue Oct 21 21:48:47 GMT 2014

Powered by FUDForum. Page generated in 0.02085 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software