Project

Profile

Help

Support #6123

closed

xsl:evaluate returns plain text instead of nodes

Added by Radu Coravu about 1 year ago. Updated 13 days ago.

Status:
Closed
Priority:
Low
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
2023-07-08
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:

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.

Actions #1

Updated by Martin Honnen about 1 year ago

Does

<xsl:variable name="var1" as="node()*">
            <xsl:evaluate xpath="$nodePath" context-item="/"/>
        </xsl:variable>

help?

Actions #2

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.

Actions #3

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.

Actions #4

Updated by Radu Coravu about 1 year ago

Thanks for the clarification and for the help Martin!

Actions #5

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.

Actions #6

Updated by Debbie Lockett 13 days ago

  • Status changed from Resolved to Closed

Please register to edit this issue

Also available in: Atom PDF