Problem with XPath with child name as a variable

Discussion in 'XML' started by tslettebo@hotmail.com, May 6, 2006.

  1. Guest

    Hi.

    I don't know if the following is possible (I haven't found it in
    examples/tutorials, or using a search, but then, it's hard to tell what
    to search for), but it seems so obvious, so I'm wondering if I just
    don't know the right syntax for it:

    I'm using XSLT and have an input XML like this:

    <root>
    <name1><value>1</value></name1>
    <name2><value>2</value></name2>
    <name3><value>3</value></name3>
    </root>

    I'd like to read the contents of the right <value> node, with the
    parent name given with a variable/string, something like:

    /root/$name/value // This gives "1", "2" or "3", depending on whether
    $value has "name1", "name2" or "name3".

    However, the above doesn't work, at least on Sablotron. Any ideas how
    to accomplish this?

    Regards,

    Terje
     
    , May 6, 2006
    #1
    1. Advertising

  2. wrote:
    > <root>
    > <name1><value>1</value></name1>
    > <name2><value>2</value></name2>
    > <name3><value>3</value></name3>
    > </root>
    >
    > I'd like to read the contents of the right <value> node, with the
    > parent name given with a variable/string, something like:
    >
    > /root/$name/value // This gives "1", "2" or "3", depending on whether
    > $value has "name1", "name2" or "name3".


    You can do that like this
    /root/*[local-name() = $name]/value

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, May 6, 2006
    #2
    1. Advertising

  3. Guest

    Ah, thanks for the quick answer.
     
    , May 6, 2006
    #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. Alastair Cameron
    Replies:
    1
    Views:
    7,423
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  2. Marc A. Criley
    Replies:
    0
    Views:
    562
    Marc A. Criley
    Dec 30, 2004
  3. Jeff Rodriguez
    Replies:
    23
    Views:
    1,141
    David Schwartz
    Dec 9, 2003
  4. Bobby Chamness
    Replies:
    2
    Views:
    2,412
    Joe Smith
    Apr 22, 2007
  5. mfglinux
    Replies:
    11
    Views:
    712
    Roberto Bonvallet
    Sep 12, 2007
Loading...

Share This Page