[XSLT21Req] new elements for bag or basket

Hello!

I suggest the introduction of two new elements in XSLT 2.1: 
xsl:bag-variable and xsl:gather-unordered-in-bag

Both of these new elements are stream friendly and fork friendly. Their 
names could be shortened (xsl:bag and xsl:gather, for example) or 
otherwise changed, but I choose to write xsl:bag-variable and 
xsl:gather-unordered-in-bag for clarity.

The aim is to simplify many XSLT transformations and to avoid the need to 
parse the same (or similar) information several times.

In the following pseudocode, I describe a way to "gather" elements in a 
bag during the transformation process during which the first (main) part 
of the output is created. The elements gathered in the bag are unordered 
(or in an unpredictable order). Thereafter (parts of) (the information 
contained in) those gathered elements may be written towards the end of 
the output. No attempt is made to predict the order of the elements as 
they are gathered in the bag. When the bag is "full", (i.e. all elements 
that should be gathered are in the bag), it should be possible to xsl:sort 
those elements before they are written to output.

Of course, the exact syntax could be discussed. Here, I write a pseudocode 
snippet to show how these new elements COULD work:

************* Pseudocode begins here! *************

xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ex="http://example.org/" version="2.1"

xsl:output method="xml" /

xsl:bag-variable name="basket" /

Now, the bag namned "basket" is created. This bag will be used to gather ex:foo and ex:baz elements.

xsl:template match="/"

some code

xsl:call-template /

more code

xsl:apply-templates /

more code

ex:foos-and-baz ex:quantity="{count($basket)}"

This was the start tag of the container for the ex:foo and ex:bag elements 
as they are written to output. The attribute ex:quantity is also set.

xsl:copy-of select="$basket"

This was a somewhat new way to use the xsl:copy-of element

xsl:sort collation="http://example.net/my-collation" /

if the xsl:sort element above is omitted, then the ex:foo and ex:baz 
elements occur in an unpredictable order within the ex:foos-and-baz 
element. Alternatively, a default sorting could be applied.

/xsl:copy-of

/ex:foos-and-baz

/xsl:template

The main template is ending here.

xsl:template match="some-element"

lots of code and calculations, with (for example) xsl:for-each, 
recursions, calls to several xsl:template elements, etc. ...

xsl:if test="something"

xsl:gather-unordered-in-bag name="basket"

ex:foo

some content for the ex:foo element

/ex:foo

/xsl:gather-unordered-in-bag

Now, one ex:foo element is added to the bag. Several other elements could be there.

/xsl:if

/xsl:template

xsl:template name="some-mame"

again lots of code and calculations, with (for example) xsl:for-each, 
recursions, calls to several xsl:template elements, etc. ...

xsl:gather-unordered-in-bag name="basket"

ex:baz /

/xsl:gather-unordered-in-bag

Now, one ex:baz element is added to the bag. Several other elements could be there.

again lots of code and calculations, with (for example) xsl:for-each, 
recursions, calls to several xsl:template elements, etc. ...

/xsl:template

Some more templates, some of which make use of the xsl:gather-unordered-in-bag element ...

/xsl:transform

************* Pseudocode ends here! *************

Possible extensions:

- Gathering not only element, but also attributes

- Gathering list elements. This could be achieved through an "as" 
attribute on the xsl:bag-variable element (such as as="xs:list"). The 
order of the list elements within the list would still be unpredictable.

These extensions would still be stream friendly and fork friendly.

Regards!

Saašha,

Received on Thursday, 12 May 2011 19:54:20 UTC