2

I need to get into a variable the internal structure of a node, the issue is that the node has different paths by different reasons. What I am doing until now is

<xsl:variable name="my_variable">
  <xsl:choose>
    <xsl:when test="One/Path/To/TheNode">
      <xsl:value-of select="One/Path/To/TheNode"/>
    </xsl:when>
    <xsl:when test="One/Different/Path/To/TheNode">
      <xsl:value-of select="One/Different/Path/To/TheNode"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="//TheNode"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:variable>

And then if I use this variable to get some subnode doing:

   <xsl:variable name="other_variable" select="$my_variable/Subnode"/>

I get this error in runtime XPath error : Invalid type Evaluating global variable var/param being computed failed, I tried too doing this:

<xsl:variable name="other_variable" select="ext:node-set($my_variable)/SubNode"/>

I don´t get any error executing the xslt, but other_variable is empty. Checking the content of my_variable doing <xsl:value-of select="$my_variable"/> or <xsl:apply-templates mode="copy" select="ext:node-set($my_variable)"/> I can see the data but without the xml structure, I mean I can see bar but not <foo>bar</bar>.

Is there any way to get this structure from a different path without use <xsl:variable name="my_variable" select="//TheNode"/>??

Thanks.

2
  • 1
    Try using xsl:copy-of instead of xsl:value-of? Commented Apr 3, 2019 at 9:18
  • woohhoo!!! Thanks @michael.hor257k it worked. I had tried with copy but I didn´t think copy-of. Please, add as an answer and I´ll accept it. Thanks!! Commented Apr 3, 2019 at 9:32

1 Answer 1

1

The xsl:value-of instruction will create a text node with the string-value of the selected node - or more precisely, the first node of the selected node-set (in XSLT 1.0).

If you want to preserve the structure, use the xsl:copy-of instruction instead.

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

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.