Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > finding nodes that don't match other nodes

Reply
Thread Tools

finding nodes that don't match other nodes

 
 
mlybarger@gmail.com
Guest
Posts: n/a
 
      01-27-2005
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

 
Reply With Quote
 
 
 
 
Joris Gillis
Guest
Posts: n/a
 
      01-27-2005
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-v...i?userid=38041)
Laudeo W3C et dona ferens
 
Reply With Quote
 
 
 
 
Mark
Guest
Posts: n/a
 
      01-27-2005
excellent, thanks Joris!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why treat text nodes as nodes? Xamle Eng XML 8 05-28-2005 01:11 PM
Text nodes and element nodes query asd Java 3 05-23-2005 10:01 AM
Looking A Nodes From Within Nodes Johnny Ooi XML 10 11-14-2004 06:55 PM
selecting nodes between other nodes Timo Nentwig XML 1 06-17-2004 04:54 AM
Reality check: Is it sensible to link XML nodes to other XML nodes in the same file? gavnosis XML 0 08-02-2003 08:22 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57