xsl-list
[Top] [All Lists]

[xsl] How to find distinct nodes by value?

2006-10-11 10:22:26
I would like to retrieve only the distinct nodes (by value) from a
"//myElement"-like  expression; <myElement> is either empty or contains
only text.

From this document

<a>
    <myElement>aaa</myElement>
    <b>
       <myElement>aaa</myElement>
       <myElement>xyz</myElement>
       <myElement>efg</myElement>
    </b>
    <c>
       <d>
           <myElement>khl</myElement>
           <myElement>xyz</myElement>
       </d>
    </c>
</a>

the result should be (the order doesn't matter)

<myElement>aaa</myElement>
<myElement>xyz</myElement>
<myElement>efg</myElement>
<myElement>khl</myElement>

In early XPath "Working Draft"s there seems to have been a function
called "distinct-nodes()" which should have done something similar but
it used the identity of the nodes.
This document still shows the function
http://www.w3.org/TR/2003/WD-xpath-functions-20030502/#func-distinct-nodes
and it was removed in
http://www.w3.org/TR/2003/WD-xpath-functions-20031112/

A replacement for this function found in
http://www.w3.org/TR/2005/WD-xpath-functions-20050404/#func-distinct-nodes-stable

basically tells that

//myElement[empty(subsequence(//myElement, 1, position()-1) intersect .)]

should work to select distinct nodes (by identity).

But I haven't been able to find a solution for distinct nodes by value.

Any suggestions?



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

<Prev in Thread] Current Thread [Next in Thread>