[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XPath to find duplicate elements

Subject: Re: XPath to find duplicate elements
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 5 Apr 2018 18:15:26 -0000
Re:  XPath to find duplicate elements
Just a thought on this.

If we can implement deep-equal($n1, $n2)  as calculating some
ValueIdentity (VI) for each of the nodes and returning

     VI1 eq VI2 ...

Then the VIs for each node can be calculated on the initial reading of
the XML document (even in streaming mode) with almost no additional
effort. If these VIs are made properties of the nodes, then we could
just compare the VIs of the nodes and avoid any repeated zip-like
comparison of the subtrees that are topped by these nodes. And this
also seems more declarative/functional.

Just my 2c.

Cheers,
Dimitre



On Thu, Apr 5, 2018 at 9:45 AM, Martin Honnen martin.honnen@xxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> On 05.04.2018 18:12, Leo Studer leo.studer@xxxxxxxxxxx wrote:
>
>> I have an xml file where I need and XPath expression to find all elements
>> that are a copy of a previous element in the same file.
>>
>> I came up with the following:
>>
>>
>> *let* *$xml* := <a>
>> <b>
>> <c>1</c>
>> <d>1</d>
>> <d>2</d>
>> </b>
>> <b>
>> <c>2</c>
>> <d>1</d>
>> <d>3</d>
>> </b>
>> <b>
>> <c>3</c>
>> <d>2</d>
>> <d>3</d>
>> </b>
>> <b>
>> <c>3</c>
>> <d>2</d>
>> <d>3</d>
>> </b>
>> </a>
>> *return*
>>
>> *$xml*//*[*let**$node1*:=.*return**some**$node2**in**$xml*//*[.<<*$node1*]
>>
*satisfies*/deep-equal/(*$node1*,*$node2*)]/(ancestor-or-self::/node/()//conc
at/(/node-name/(.),1+/count/(preceding-sibling::*)),'&#10;')
>>
>> which gives
>>
>>   a1 b2 d2
>>   a1 b3 d2
>>   a1 b3 d3
>>   a1 b4
>>   a1 b4 c1
>>   a1 b4 d2
>>   a1 b4 d3
>>
>>
>> This is actually not to bad. However, I would like the correct position of
>> the copy. Instead of preceding-sibling::/* /in the count() function, I
would
>> like to write something like preceding-sibling::/element(node-name(.)).
>> /Unfortunately the processor does not allow that ;-(b&
>
>
> The code with $xml := <a>...</a> looks like XQuery to me, not like XSLT or
> XPath. That aside, what do you want pseudo syntax
>   preceding-sibling::element(node-name(.))
> to compute? If you want to select all elements and compare them to the
> node-name() of another node you can certainly use
>   preceding-sibling::*[node-name() = node-name($n)]
> where you simply would need to make sure you define $n previously with a
> "let", as you have done at another place in your code.
>
> Also XPath now has a "path" function which returns an XPath expression with
> positional predicates so perhaps you don't need to construct the
> name/position pairs on your own if you have access to the latest XPath
> version.
>



--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they
write all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.