Nodeset Difference AKA Nodeset Reduction

Discussion in 'XML' started by Bryan Galvin, Sep 28, 2004.

  1. Bryan Galvin

    Bryan Galvin Guest

    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
    Bryan Galvin, Sep 28, 2004
    #1
    1. Advertising

  2. Bryan Galvin

    Joris Gillis Guest

    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
    Joris Gillis, Sep 28, 2004
    #2
    1. Advertising

  3. Bryan Galvin

    Bryan Galvin Guest

    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

    (Joris Gillis) wrote in message news:<>...
    > 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
    Bryan Galvin, Sep 29, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick

    Bus reduction

    Patrick, Jun 7, 2004, in forum: VHDL
    Replies:
    1
    Views:
    546
    Egbert Molenkamp
    Jun 7, 2004
  2. Bryan Galvin

    NodeSet Reduction

    Bryan Galvin, Jun 9, 2004, in forum: XML
    Replies:
    3
    Views:
    394
    Bryan Galvin
    Jun 14, 2004
  3. Elhanan
    Replies:
    1
    Views:
    375
    Elhanan
    May 11, 2006
  4. A B Carter

    efficient list reduction

    A B Carter, May 11, 2004, in forum: Python
    Replies:
    2
    Views:
    538
    Paul Rubin
    May 11, 2004
  5. JohnJSal
    Replies:
    13
    Views:
    428
    John Salerno
    Nov 4, 2006
Loading...

Share This Page