Project

Profile

Help

Bug #3748

closed

Text value templates don't work as child of xsl:variable

Added by Michael Kay about 6 years ago. Updated almost 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
XSLT conformance
Sprint/Milestone:
-
Start date:
2018-04-17
Due date:
% Done:

100%

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

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>
Actions #1

Updated by Michael Kay about 6 years ago

  • 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).

Actions #2

Updated by Michael Kay about 6 years ago

Added XSLT 3.0 test case cvt-042

Actions #3

Updated by Michael Kay about 6 years ago

  • 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.

Actions #4

Updated by O'Neil Delpratt almost 6 years ago

  • 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