Thanks! I did check  though
8.2 Conditional Processing with xsl:choose
and even 5.7 sequence constructor
because I thought that was what was going on.

so which statement is constructing the new node, xsl:choose or xsl:when?

also, xquery, sequence constructor (parens) do not appear to 'work' the same, sequence seems preserved?

-Paul


From: Andrew Welch <andrew.j.welch@gmail.com>
To: Mailing list for the SAXON XSLT and XQuery processor <saxon-help@lists.sourceforge.net>
Cc: Paul M <pjmaip@yahoo.com>
Sent: Thursday, May 17, 2012 9:28 AM
Subject: Re: [saxon] saxon or just xslt2.0

On 17 May 2012 14:05, David Rudel <fwqhgads@gmail.com> wrote:
> I suspect in one case your variable is being treated as a virtual document
> node and in the other case it is being treated as a sequence of nodes. This
> is an important nuance I only recently discovered myself.
>
> You can see the difference by comparing the following:
> <xsl:variable name="testme">
> <xsl:sequence select="a"/>
> <xsl:sequence select="b"/>
> </xsl:variable>

The thing to be aware of is the implicit document node creation within
the variable:

<xsl:variable name="foo">
    <foo/>
</xsl:variable>

is the same as:

<xsl:variable name="foo">
    <xsl:document>
        </foo/>
    </xsl:document>
</xsl:variable>

In both cases $foo contains a document node with the element <foo/> as a child.

If you specify the sequence constructor (the 'as' attribute) such as:

<xsl:variable name="foo" as="element(foo)">
    <foo/>
</xsl:variable>

then $foo now just contains the element <foo/>

If you explicitly create the document node with that same sequence constructor:

<xsl:variable name="foo" as="element(foo)">
    <xsl:document>
        <foo/>
    </xsl:document>
</xsl:variable>

....then you get an error because the variable contains a document
node instead of the element <foo/>

So the moral of the story is always specify the 'as' attribute, and if
you really want a document node, then use
as="document-node(root-element)" and explicitly create it.


--
Andrew Welch
http://andrewjwelch.com