#557 TextFragment trees

Michael Kay

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

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


<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'"/>


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


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

Sign up for the SourceForge newsletter:

No, thanks