Re: [xsl] XSLT result tree fragment, with XSLT 3.0 and xsl:variable

Subject: Re: [xsl] XSLT result tree fragment, with XSLT 3.0 and xsl:variable
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 10 Apr 2023 14:15:45 -0000
Am 4/10/2023 um 1:41 PM schrieb Mukul Gandhi mukulg@xxxxxxxxxxxxxxxxx:
Hi all,
B  B While comparing the, data models of XPath 1.0 and 3.1 languages (in
the context of XSLT transformations), I noticed that, XSLT 3.0 doesn't
have (i.e, it doesn't define) a data type named as "result tree
fragment" Whereas, the data type "result tree fragment" is available
with XSLT 1.0.

With respect to this topic, I've been comparing the semantics of XSLT
xsl:variable instruction within 1.0 and 3.0 versions of XSLT language.

1) From the XSLT 1.0 spec
A variable is a name that may be bound to a value. The value to which
a variable is bound (the value of the variable) can be an object of
any of the types that can be returned by expressions.
There is a region of the stylesheet tree within which the binding is
visible.

Result Tree Fragments
Variables introduce an additional data-type into the expression
language. This additional data type is called result tree fragment. A
variable may be bound to a result tree fragment instead of one of the
four basic XPath data-types (string, number, boolean, node-set). A
result tree fragment represents a fragment of the result tree.

2) From the XSLT 3.0 spec
The value of the variable is computed using the expression given in
the select attribute or the contained sequence constructor.

I think, from the point of view of XSLT language in general, "result
tree fragment" (from XSLT 1.0) and "sequence constructor" (from XSLT
3.0) both serialize into the XSLT transformation'sB output (which
typically would be XML for this discussion). The XSLT 3.0 sequence
constructor, shall result in a value with a XPath 3.1 data type
item()+. The XSLT 3.0 language, defines "sequence constructor" as : A
sequence constructor is a sequence of zero or more sibling nodes in
the stylesheet that can be evaluated to return a sequence of nodes,
atomic values, and function items.

It seems to me that, XSLT 1.0's "result tree fragment" (before being
serialized to the output XML) is a well-formed XML fragment. Whereas,
XSLT 3.0's sequence constructor is also a well-formed XML fragment,
that evaluates to a sequence of nodes, atomic values, and function
items. Other than, the XPath 3.1 function items (which is not
available with XSLT 1.0/XPath 1.0), XSLT 3.0's sequence of nodes and
atomic values looks to me, an intermediate compiler representation
that is finally transformed into the XML document available as a
result of XSLT transformation.


With XSLT 3 and XQuery 3.1 serialization having output methods adaptive and json the sequence constructor is often used to construct contents that doesn't serialize as XML at all but for instance as JSON; even with an XSLT 2.0 processor you can construct a sequence of e.g. attribute nodes that could not be serialized standalone as XML.

And your XSLT result is not necessarily serialized at all, you can read
the raw transformation result (e.g. a sequence of items in general),
depending on the XSLT processor's API.

Thus if your request is meant to find an equivalent to XSLT 1.0 result
tree fragment in an XSLT 2 or 3 intermediary tree (fragment) then I
think your description is fine; but you can't "map" the more diverse
options of XSLT 2 and 3 sequence constructors back to an XSLT 1.0 result
tree fragment, there are sequences you can't put in an XML tree
(fragment) or serialize as an XML tree (fragment).

Current Thread