finding nodes that don't match other nodes

Discussion in 'XML' started by mlybarger@gmail.com, Jan 27, 2005.

  1. Guest

    i'm trying to use xpath to find nodes that don't match any other nodes
    (of a different type). here's an example xml:

    <a>
    <b>
    <c>one</c>
    <c>three</c>

    <d>
    <e>one</e>
    <e>three</e>
    <e>five</e>
    </d>
    </a>

    what i want to find are all the e nodes that don't have a matching c
    node (five in this case). any pointers would be most appreciated!
    ~thanks
     
    , Jan 27, 2005
    #1
    1. Advertising

  2. Joris Gillis Guest

    Tempore 17:52:11, die Thursday 27 January 2005 AD, hinc in foro {comp.text.xml} scripsit <>:

    > <a>
    > <b>
    > <c>one</c>
    > <c>three</c>
    >
    > <d>
    > <e>one</e>
    > <e>three</e>
    > <e>five</e>
    > </d>
    > </a>
    >
    > what i want to find are all the e nodes that don't have a matching c
    > node (five in this case). any pointers would be most appreciated!

    Hi,

    A short, but CPU unfriendly method is this:
    <xsl:template match="a">
    <xsl:apply-templates select=".//e[not(.=//c)]"/>
    </xsl:template>

    A key approach could be used for better performance:
    <xsl:key name="node" match="c" use="."/>

    <xsl:template match="a">
    <xsl:apply-templates select=".//e[not(key('node',.))]"/>
    </xsl:template>

    regards,
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    Laudeo W3C et dona ferens
     
    Joris Gillis, Jan 27, 2005
    #2
    1. Advertising

  3. Mark Guest

    excellent, thanks Joris!
     
    Mark, Jan 27, 2005
    #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. hiwa
    Replies:
    0
    Views:
    653
  2. gavnosis
    Replies:
    0
    Views:
    537
    gavnosis
    Aug 2, 2003
  3. Victor
    Replies:
    2
    Views:
    658
    Victor
    May 17, 2004
  4. Timo Nentwig

    selecting nodes between other nodes

    Timo Nentwig, Jun 16, 2004, in forum: XML
    Replies:
    1
    Views:
    428
    Patrick TJ McPhee
    Jun 17, 2004
  5. ekzept
    Replies:
    0
    Views:
    390
    ekzept
    Aug 10, 2007
Loading...

Share This Page