XSLT 1.0: Select children based on arbitrary node?

Z

Zachary Turner

I want to select some nodes based on whether or not another node
exists in another part of the document with the exact same name.


For example,

<special-location>
<special-element value="some-element"/>
<special-element value="some-element-two"/>
</special-location>

<root>
<some-element .../>
<some-element-two .../>
<some-other-element .../>
</root>


What I want to do is select only the first and second elements under
<root>, and ignore the third element since there is no <special-
element> node with @value=some-other-element.

Is this possible with a simple XPath, or do I need to use more
complicated logic and branching structures?
 
B

Bjoern Hoehrmann

* Zachary Turner wrote in comp.text.xml:
I want to select some nodes based on whether or not another node
exists in another part of the document with the exact same name.

For example,

<special-location>
<special-element value="some-element"/>
<special-element value="some-element-two"/>
</special-location>

<root>
<some-element .../>
<some-element-two .../>
<some-other-element .../>
</root>


What I want to do is select only the first and second elements under
<root>, and ignore the third element since there is no <special-
element> node with @value=some-other-element.

Well it would be something like

*[ //special-element/@value = local-name() ]

This selects a child element of the context node if there is a special-
element element whose value attribute has the same value as the local-
name of the current node.
 

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,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top