1

I have the following XML:

<root>
  <name>The name</name>
  <long>
    <path>
      <value>Some Value</value>
    </path>
  </long>
  <field>/root/name</field>
  <field>/root/long/path/value</field>
</root>

and I want to select these paths in the field tags however, when I try the following:

<xsl:value-of select="/root/field[1]" />

all I get is the text value of the field. Is there a way of selecting the correct node from those values?

0

3 Answers 3

1

You need some form of dynamic evaluation. I believe there is a non-standard function eval() (or evaluate() in some implementations) that allows you to use dynamic xpath.

Which XPath processor are you using, and XPath 1.0 or 2.0?

Sign up to request clarification or add additional context in comments.

Comments

0

Such kind of dynamic evaluation is not supported even in XSLT 2.0.

Maybe the XSLT processor you are using supports EXSLT's dyn:evaluate() extension function?

Comments

0

If you want the node that contains "/root/node" then your xpath would be:

//*[.='/root/name']

this is called a predicate, where the* matches any node and the . is the current node.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.