1

For the following xml document:

<company>
   <employee>
      <name>John Andrews</name>
      <age>23</age>
      <salary>4000</salary>
      <division>Accounting</division>
   </employee>
</company>

I have the xsl like

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:value-of select="company/employee/name"/>

    <xsl:variable name="test">
      <xsl:text>company/employee/name</xsl:text>
    </xsl:variable>

    <xsl:evaluate xpath="$test"/>

  </xsl:template>
</xsl:stylesheet>

How can I use $test variable in xsl:evaluate in order to get the same result as in the:

<xsl:value-of select="company/employee/name"/>

Is it possible?

pshemek
  • 1,369
  • 4
  • 17
  • 33

1 Answers1

2

You need to set the context item with e.g.

    <xsl:evaluate xpath="$test" context-item="."/>
Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • can the output of this be starred in a variable like: – pshemek Nov 10 '17 at 12:23
  • Have you tried that and run into a problem? What type do you want that variable to have, what kind of data value? Your path `company/employee/name` select a sequence of elements and the `xsl:evaluate` will return that sequence, if you want to bind that sequence to a variable use e.g. ``. You might want to open a new question stating with more detail what you want to achieve. – Martin Honnen Nov 10 '17 at 12:38