Re: [xsl] empty sequence as complex content

Subject: Re: [xsl] empty sequence as complex content
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 4 Jul 2019 18:00:22 -0000
Saxon is getting this wrong: zero-length text nodes should never exist, unless
they are parentless.

What's happening is that the variable "x" satisfies all the conditions for a
"text-fragment" tree. Because constructs like

<xsl:variable name="z">
  <xsl:value-of select="23"/>
</xsl:variable>

are encountered so frequently, Saxon uses a lightweight data structure to
represent them; this represents a tree comprising a document node with a
single text node child. The optimization logic runs "there are no child
instructions producing anything other than text nodes", therefore this data
structure is used, and it then behaves as if there is a single zero-length
text node.

I suspect the same problem will arise if there's an <xsl:value-of/> child
whose select expression evaluates to a zero-length string.

Michael Kay
Saxonica

> On 4 Jul 2019, at 18:01, David Carlisle d.p.carlisle@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> The following stylesheet generates a variable x using a sequence
> constructor that evaluates to an empty sequence...
>
> <xsl:stylesheet version="3.0"
>        xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>        xmlns:xs="http://www.w3.org/2001/XMLSchema";
>>
>
> <xsl:variable name="x">
>  <xsl:sequence select="()"/>
> </xsl:variable>
>
>
> <xsl:template match="/">
>  <xsl:message select="'C1:',
>               $x instance of xs:string,
>               string-length($x)
>               "/>
>  <xsl:message select="'C2:',
>               $x instance of document-node(),
>               count($x/node()),
>               $x/node() instance of text(),
>               $x/text()/string-length(.)
>               "/>
> </xsl:template>
>
> </xsl:stylesheet>
>
>
> $x is a variable that is a document node with a text node child the
> text node having zero length.
>
>
>
> I just read https://www.w3.org/TR/xslt-30/#constructing-complex-content
> 10 times but still don't see where the text node came from
>
>
> having the xsl:sequence there means it avoids the XSLT 1 special case
> returning a string, and not having an as= attribute means there is an
> implicit  document node generated, but I would expected that $x was
> just a document node with no children, but saxon (Saxon-HE 9.9.0.1J)
> produces
>
>
> $ saxon9 ev.xsl ev.xsl
> C1: false 0
> C2: true 1 true 0
> <?xml version="1.0" encoding="UTF-8"?>
>
>
>
> If someone could point me at the right bit of the spec I think I'm
> missing a step somewhere...
>
>
> David

Current Thread