Reputation: 1419
For the following 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>
I use this XSL to store the value in a variable using xsl:evaluate
and then output the value from name node that is stored in in $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>
Upvotes: 0
Views: 683
Reputation: 167716
With the namespace declaration you have the type annotation of the variable needs to be
<xsl:variable name="names" as="element(pi:name)*">
<xsl:evaluate xpath="$test" context-item="."/>
</xsl:variable>
Upvotes: 0