Bug #3748
closed
Text value templates don't work as child of xsl:variable
Category:
XSLT conformance
Applies to branch:
9.8, trunk
Fix Committed on Branch:
9.8, trunk
Fixed in Maintenance Release:
Description
See https://stackoverflow.com/questions/49882695/text-value-templates-and-xslvariable
The following example demonstrates the problem:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"
xmlns="http://www.w3.org/1999/xhtml/"
version="3.0" expand-text="yes">
<xsl:output method="xhtml" html-version="5"/>
<xsl:template name="xsl:initial-template">
<xsl:variable name="t">Source: {document-uri(.)}</xsl:variable>
<html>
<body>
<p><xsl:value-of select="$t"/></p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
- Status changed from New to In Progress
The problem is that there is code in xsl:variable that optimizes for the case where the content of the instruction is a single text node, and this code has not been updated to allow for text value templates. In fact we compile the text value template correctly, and then discard the result to substitute a fixed value for the variable.
For a workaround, add the attribute as="xs:string". In fact, it's probably a good idea to add this anyway, since the variable is almost certainly intended to be used as a string (not as a document node containing a single text node child, which is what you get without the "as" attribute).
Added XSLT 3.0 test case cvt-042
- Status changed from In Progress to Resolved
- Applies to branch 9.8, trunk added
- Fix Committed on Branch 9.8, trunk added
Patch committed to SourceBinding.java in 9.8 and trunk.
The patch ensures that the "constantText" optimization is used only if the compiled expression is of the form ValueOf(StringLiteral). Previously it was triggered whenever the content of an xsl:variable (or other variable binding element) (with no as attribute) was a single text node.
- Status changed from Resolved to Closed
- % Done changed from 0 to 100
- Fixed in Maintenance Release 9.8.0.12 added
Bug fix applied in the Saxon 9.8.0.12 maintenance release.
Please register to edit this issue
Also available in: Atom
PDF