0

对于以下 XML:

<?xml version="1.0" encoding="UTF-8"?>
<pi:Payroll_Extract_Employees xmlns:pi="urn:com.workday/picof">
   <pi:company>
      <pi:employee>
         <pi:name>John Andrews</pi:name>
         <pi:age>23</pi:age>
         <pi:salary>4000</pi:salary>
         <pi:division>Accounting</pi:division>
      </pi:employee>
   </pi:company>
</pi:Payroll_Extract_Employees>

我使用这个 XSL 将值存储在一个变量中xsl:evaluate,然后从存储在$names(“John Andrews”)中的名称节点输出值:

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

xmlns:pi="urn:com.workday/picof">
        <xsl:output method="text"/>
            <xsl:template match="pi:Payroll_Extract_Employees/pi:company">
                <xsl:variable name="test">
                <xsl:text>pi:employee/pi:name</xsl:text>
            </xsl:variable>
                <xsl:variable name="names" as="element(name)*">
                <xsl:evaluate xpath="$test" context-item="."/>
            </xsl:variable>
                <xsl:value-of select="$names"/>
            </xsl:template>
    </xsl:stylesheet>
4

1 回答 1

0

使用命名空间声明,您需要变量的类型注释

    <xsl:variable name="names" as="element(pi:name)*">
        <xsl:evaluate xpath="$test" context-item="."/>
    </xsl:variable>
于 2017-11-10T13:20:49.750 回答