1

对于以下 xml 文档:

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

我有xsl之类的

<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>

如何在 xsl:evaluate 中使用 $test 变量以获得与以下相同的结果:

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

可能吗?

4

1 回答 1

2

您需要使用例如设置上下文项

    <xsl:evaluate xpath="$test" context-item="."/>
于 2017-11-10T11:03:24.847 回答