#557 TextFragment trees

v8.7.3
closed
5
2012-10-08
2006-06-29
Michael Kay
No

In XSLT, when a construct such as the following is used
in a stylesheet:

<xsl:variable name="t">text</xsl:variable>

or

<xsl:variable name="t"><xsl:value-of select="expr"></xsl:variable>

Saxon internally creates a special kind of tree called
a text fragment tree. This has only two nodes, a
document ndoe and a text node.

When a path expression is used with the root node of a
text fragment tree as the context node, using the self,
ancestor-or-self, or descendant-or-self axis, Saxon
returns the document node even if it does not match the
node-test. For example count($t/descendent-or-self::*)
will return 1 when it should return 0.

This bug has been present since time immemorial...

NOTE: in the vast majority of cases it is better to
rewrite the above expressions as

<xsl:variable name="t" select="'text'"/>

or

<xsl:variable name="t" select="string(expr)"/>

so that the value of the variable is a string rather
than a document node.

A further glitch is that with the expression $t/self::
Saxon detects at compile time that self::
cannot
select any nodes, but the warning message that it
produces is garbled. This applies not only to a text
fragment tree, but to any path expression that selects
self::* starting at a document node.

Discussion

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks