XSLT 1.0: Select children based on arbitrary node?

Discussion in 'XML' started by Zachary Turner, May 30, 2007.

  1. 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?
     
    Zachary Turner, May 30, 2007
    #1
    1. Advertising

  2. * 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.
    --
    Björn Höhrmann · mailto: · http://bjoern.hoehrmann.de
    Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
    68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
     
    Bjoern Hoehrmann, May 30, 2007
    #2
    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. Replies:
    0
    Views:
    1,470
  2. Michael Reiche
    Replies:
    3
    Views:
    10,855
    Michael Reiche
    Feb 5, 2004
  3. bearclaws
    Replies:
    3
    Views:
    579
    bearclaws
    Mar 10, 2005
  4. Replies:
    18
    Views:
    2,762
    Joseph Kesselman
    Oct 4, 2006
  5. njsimha
    Replies:
    0
    Views:
    784
    njsimha
    Sep 16, 2008
Loading...

Share This Page