Nodeset Difference AKA Nodeset Reduction

B

Bryan Galvin

Hi all,

I posted a message on this topic before, but now I have a request for
help. Previously "A. Bolmarcich" answered this query for me, but the
problem has changed slightly...

I have two node-sets
a=
<values>
<value>A</value>
<value>B</value>
<value>C</value>
<value>D</value>
</nodes>

and b=
<values>
<value>A</value>
<value>B</value>
</values>

How can I create a third nodeset 'c' which contains all nodes from 'a'
that DO NOT EXIST in 'b'.

If 'b' was a single-node set
b =
<values>
<value>A</value>
</values>
So the following expression ( as provided by A. Bolmarcich ) worked in
this case: <xsl:variable name="c" select="$a[. != $b]"/>

I have been studying the XPATH spec and trying to extend this
expression for use with 'b' as a multi-node set. I suspect that it is
not possible to perform this operation in one expression. A solution I
do have is this:

<xsl:variable name="c">
<xsl:for-each select="$a">
<xsl:if test="count($b[. != current()/value]) = 0">
<xsl:copy-of select="current()"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>

Any suggestions if this is possible in one expression?

Bryan Galvin
 
J

Joris Gillis

Hi,

I think this expression might do the trick.

<xsl:variable name="c">
<xsl:copy-of select="$a/values/value[not(contains($b,.))]"/>
</xsl:variable>

However, this only works under certain conditions of the values in $a
en $b.

As far as I know, the root of the problem (nodeset difference) cannot
be handled in one expression yet.
I do not doubt, however, that future versions of Xpath will allow all
kinds of node-set operations.


Joris Gillis
 
B

Bryan Galvin

Joris,

I succeeded in creating the expression to fix this problem. Not long
after I posted the message I tried this.....

<xsl:variable name="c" select="$a/value[ not( . = $b/value ) ]"/>

I also tried you suggestion...I modified it slightly to look like
this...

<xsl:variable name="d">
<xsl:copy-of select="$a/value[not(contains($b/value,.))]"/>
</xsl:variable>

And got the following results.....
c =
<values>
<value>A</value>
<value>B</value>
<value>D</value>
</value>

Thank you for the response,

Bryan Galvin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top