Re: [xsl] compare two node sets

Subject: Re: [xsl] compare two node sets
From: "Piez, Wendell A. (Fed) wendell.piez@xxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 21 Jan 2020 17:21:53 -0000
Wolfhart,



Indeed, my solution ignores that distinction, and it is a feature. The
signature logic neatly encapsulates how one wishes normalization to occur over
the names (or other features contributing to 'identity'), or not, as the case
may be. p




Cheers, Wendell



-----Original Message-----
From: Wolfhart Totschnig wolfhart.totschnig@xxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Tuesday, January 21, 2020 11:35 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] compare two node sets



Hi Wendell,



Thank you for your solution. I have a question about it, which has to do with
the fact that, in my case, the <author>/<director> elements also may have a
<middle> child element, which I did not mention in my original post. Now, if I
understand correctly, your solution does not differentiate between



        <director>

           <first>J.</first>

           <middle>R.</first>

           <last>Doe</last>

        </director>



and



        <director>

           <first>J. R.</first>

           <last>Doe</last>

        </director>



Is that right? (I am not saying that this is necessarily a problem. It may
even be seen as a feature rather than a bug. I just want to be sure that I
understand the solution correctly.)



Best,

Wolfhart





On 21.01.20 12:42, Piez, Wendell A. (Fed)
wendell.piez@xxxxxxxx<mailto:wendell.piez@xxxxxxxx> wrote:

> Hi,

>

> Another solution not yet suggested in this thread is to avoid deep-equal()
and rely on a signature function.

>

> So for example,

>

> <xsl:function name="f:signature" as="xs:string">

>    <xsl:param name="who" as="node()"/>

>    <xsl:value-of select="string-join($who/(first, last), ' ')"/>

> </xsl:function>

>

>

> Then your list of author-directors is

> //author[f:signature(.)=parent::film/child::director/f:signature(.)]

>

> (Or the other way around.)

>

> Wrap the expression in the filter in not() to retrieve authors who did not
direct, etc.

>

> One advantage of this approach is it's easy to adjust the signature logic to
real-world exigencies.

>

> Cheers, Wendell

>

> -----Original Message-----

> From: Wolfhart Totschnig
wolfhart.totschnig@xxxxxxxxxxx<mailto:wolfhart.totschnig@xxxxxxxxxxx>

>
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx<mailto:xsl-list-service@xxxxxxxxxxxx
rytech.com>>

> Sent: Sunday, January 19, 2020 4:22 PM

> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx<mailto:xsl-list@xxxxxxxxxxxxxxxxxxxxxx>

> Subject: Re: [xsl] compare two node sets

>

> Thank you, David, Michael, and Liam for the prompt replies! Michael's
solution seems to be the simplest to implement. I use Saxon 9 HE, so XPath 2.0
should be okay. And, indeed, quadratic performance should not be an issue.
However, Saxon throws the following error:

>

> XPST0003: Unexpected token "every" at start of expression

>

> Is there a typo in the expression? I used the expression as given:

>

> <xsl:when test="count(//director) eq count(//author) and every $d in

> //director satisfies some $a in //author satisfies deep-equal($d/*,

> $a/*)">

>

> To clarify, the context node is the <film> element.

>

> Wolfhart

>

>

> On 19.01.20 17:55, Liam R. E. Quin
liam@xxxxxxxxxxxxxxxx<mailto:liam@xxxxxxxxxxxxxxxx> wrote:

>> On Sun, 2020-01-19 at 20:37 +0000, Wolfhart Totschnig

>> wolfhart.totschnig@xxxxxxxxxxx<mailto:wolfhart.totschnig@xxxxxxxxxxx>
wrote:

>>> Hello,

>>>

>>> I have an XSL/XPath problem to which I cannot find the solution. I

>>> have an xml file with data about films, in the following form

>>> (simplified):

>>>

>>> [..]

>>> . By contrast, in the following example the test should return

>>> <false>:

>>>

>>>       <film>

>>>          <title>M</title>

>>>          <director>

>>>             <first>Fritz</first>

>>>             <last>Lang</last>

>>>          </director>

>>>          <author>

>>>             <first>Thea von</first>

>>>             <last>Harbou</last>

>>>          </author>

>>>          <author>

>>>             <first>Fritz</first>

>>>             <last>Lang</last>

>>>          </author>

>>>       </film>

>> Why?

>>

>> As stated,

>>    <xsl:mode on-no-match="shallow-copy" />

>>

>>     <xsl:template match="/">

>>       <xsl:apply-templates select="/films/film[

>>           some $a in author satisfies

>>           (

>>               ($a/first = director/first)

>>               and ($a/last = director/last)

>>           )

>>       ]"/>

>>     </xsl:template>

>>

>> Liam

Current Thread