RE: [XSLT2.0] variable preceding sort in for-each

> 
>   Some XSLT 2.0 constructs like xsl:for-each allow xsl:sort* in their
> content model, it is however defined that no other xsl:* elements may
> precede xsl:sort in these cases. It happens that you want to use sort
> expression later in the body of the respective construct and 
> would thus
> like to assign it to a variable,
> 
>   <xsl:for-each ...>
>     <xsl:variable ... />
>     <xsl:sort ... />
>     ...
> 
> which is not allowed, which is rather counter-intuitive. Please allow
> xsl:variable to precede xsl:sort in xsl:for-each and 
> xsl:for-each-group
> (maybe others I did not check whether it makes sense anywhere 
> else too).
> 

The semantics of this would be very complicated. It would imply that the
variable is computed with a context based on the unsorted sequence. How
would this extend to:

   <xsl:for-each ...>
     <xsl:variable ... />
     <xsl:sort ... />
     <xsl:variable ... />
     <xsl:sort ... />

Would a call on position() in the second variable reflect the position of
the item after applying the first sort key and before applying the second?

I agree that there are cases in 1.0 where computing a sort key is difficult.
However, I think that XSLT 2.0 already provides adequate remedies:

(a) you can compute the sort key using a call to a stylesheet function
(xsl:function)

(b) you can compute the sort key using a sequence constructor

<xsl:sort>
  <xsl:variable ...>
  <xsl:sequence select= .../>
</xsl:sort>

This is a personal response, but as the official public comment period is
closed, I'm not going to place this on the WG agenda unless another WG
member asks for it to be added. The XSL WG is currently happy to accept
comments that report problems in the spec, but not requests for new
features.

Regards,

Michael Kay

Received on Saturday, 17 April 2004 04:20:39 UTC