Support #6123
closed![Author: Radu Coravu](https://www.gravatar.com/avatar/765896f3e900dbcce565dbf8425cc7e7?rating=PG&size=50&default=https%3A%2F%2Fassets.plan.io%2Fimages%2Fdefault_avatar.png)
xsl:evaluate returns plain text instead of nodes
0%
Description
If we were to run with Saxon 11 this XSLT code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
xmlns:saxon="http://saxon.sf.net/"
version="3.0">
<xsl:template match="/">
<xsl:param name="nodePath" select="'/root[1]/a[1]/text()[1]'" as="xs:string"></xsl:param>
<xsl:variable name="var1">
<xsl:evaluate xpath="$nodePath" context-item="/"/>
</xsl:variable>
<xsl:variable name="var2" select="saxon:evaluate($nodePath)">
</xsl:variable>
<xsl:copy-of select="$var1/parent::*"/>
<xsl:copy-of select="$var2/parent::*"/>
</xsl:template>
</xsl:stylesheet>
on this XML document:
<root>
<a>dsadas</a>
</root>
The saxon:evaluate returns a text node which has context, it can go back to its parent element. The xsl:evaluate returns a plain string which can no longer be used to match its ancestors.
We use such node matches when computing xpath contexts for quick fixes.
So with Saxon 12 we can no longer use saxon:evaluate and the xsl:evaluate is not quite compatible.
Updated by Martin Honnen about 1 year ago
Does
<xsl:variable name="var1" as="node()*">
<xsl:evaluate xpath="$nodePath" context-item="/"/>
</xsl:variable>
help?
Updated by Radu Coravu about 1 year ago
Thanks Martin, this does work! I was somehow expecting the variable without the @as to perfectly return the type of the content inside it.
Updated by Martin Honnen about 1 year ago
No, an xsl:variable
without an as
attribute and without a select
attribute always creates a new document node whose children are formed by the content constructor inside of the xsl:variable
, i.e. in your case the items returned by the xsl:evaluate
. Thus, if you select a text node, the variable holds a document node with that text node as its child.
Updated by Radu Coravu about 1 year ago
Thanks for the clarification and for the help Martin!
Updated by Michael Kay about 1 year ago
- Tracker changed from Bug to Support
- Status changed from New to Resolved
Thanks Martin, correct explanation as ever.
Please register to edit this issue