finding nodes that don't match other nodes

M

mlybarger

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
 
J

Joris Gillis

Tempore 17:52:11 said:
<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,
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top