W3C home > Mailing lists > Public > public-qt-comments@w3.org > May 2011

Re: [XSLT21Req] new elements for bag or basket

From: Michael Kay <mike@saxonica.com>
Date: Fri, 13 May 2011 00:29:39 +0100
Message-ID: <4DCC6D63.4070408@saxonica.com>
To: public-qt-comments@w3.org
Many thanks for this contribution, Saašha: the working group will look 
at the proposal in due course.

I think it would be very useful if you could describe this in the form 
of a use case: that is, a transformation that needs to be performed, and 
which is assisted by these proposed constructs. It would be useful to 
give a complete worked solution to this transformation using these 
constructs, and this will enable the WG to consider how else such a 
transformation might be achieved and how this proposed feature compares 
with other possible solutions.

At first sight, the idea of such a construct for gathering working data 
during a streaming pass of the input document looks well aligned with 
ideas that the WG has been developing since our last published draft. 
We've looked at a number of possible data structures for meeting such 
requirements, and the use cases we have examined appear to be well 
served by maps, which will feature in the next working draft. It's 
unclear to me from your description how similar or different your 
bags/baskets are to our maps.

Best regards,

Michael Kay
(personal response)

On 12/05/2011 20:47, Saašha Metsärantala wrote:
> 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 23:30:04 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 27 March 2012 18:15:12 GMT