[xsl] compare two node sets

Subject: [xsl] compare two node sets
From: "Wolfhart Totschnig wolfhart.totschnig@xxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 19 Jan 2020 20:36:34 -0000
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):

B B  <film>
B B B B B  <title>The big Lebowski</title>
B B B B B  <director>
B B B B B B B B  <first>Joel</first>
B B B B B B B B  <last>Coen</last>
B B B B B  </director>
B B B B B  <director>
B B B B B B B B  <first>Ethan</first>
B B B B B B B B  <last>Coen</last>
B B B B B  </director>
B B B B B  <author>
B B B B B B B B  <first>Ethan</first>
B B B B B B B B  <last>Coen</last>
B B B B B  </author>
B B B B B  <author>
B B B B B B B B  <first>Joel</first>
B B B B B B B B  <last>Coen</last>
B B B B B  </author>
B B  </film>

I would like to test whether the director(s) of the film are the same as its writer(s) (here called "authors"). That is, I want to test whether for each <director> element there is an <author> element with the same child elements, and vice versa (i.e., for each <author> element a corresponding <director> element). So, in the above case, the test should return <true>. Note that the order of the <director>/<author> elements should not matter. By contrast, in the following example the test should return <false>:

B B  <film>
B B B B B  <title>M</title>
B B B B B  <director>
B B B B B B B B  <first>Fritz</first>
B B B B B B B B  <last>Lang</last>
B B B B B  </director>
B B B B B  <author>
B B B B B B B B  <first>Thea von</first>
B B B B B B B B  <last>Harbou</last>
B B B B B  </author>
B B B B B  <author>
B B B B B B B B  <first>Fritz</first>
B B B B B B B B  <last>Lang</last>
B B B B B  </author>
B B  </film>

How can this be done?

To explain the purpose of this: When the test comes out true, the output will be "Written and directed by [names]", whereas otherwise it will be "Written by [names]. Directed by [names]".

Thanks in advance for your help!

Wolfhart

Current Thread