[xquery-talk] Xquery to xslt conversions

David Carlisle davidc at nag.co.uk
Wed Jan 11 17:20:15 PST 2006

  Also, how are you handling the XQuery "order by" problem: what XSLT code do
  you generate for pathological cases like

  for $x in 1 to 10, $y in 100 to 200
  order by $y, $x
  return $x + $y

Actually as I document in the xq2xsl notes, that is the non-pathological
case where a somewhat simpler and more efficient mapping to xslt can be
used. The two ranges are independent so can be pulled out of the loop
and you know in advance how many tuples you need to iterate over.
I document the simpler mapping at 

but actually I only implement the more general case where the range of
the later variables depends on earlier variables, for example

for $x in 1 to 10, $y in $x to 200
order by $y, $x
return $x + $y

I've just noticed that my documentation of the general case ends with

     The main disadvantage of all this is that the expressions F($i)
     above that generate the sequences get evaluated multiple times and
     might be expensive, This could be optimised by the convertor (for
     example detecting the case that the sequences do not depend on the
     range variables, and so using the method in the previous section,
     but some of the optimisations are probably more easily done by the
     XSLT compiler. For example I believe Saxon does not evaluate
     variables that are never used, so there is no real need for the
     convertor to analyse the expressions and see if all the variables
     defined are needed.

Is my trust in saxon justified here?

or should I work harder and explictly omit the expressions

         <xsl:variable name="xq:p2" select="$xq:index[2]"/>
         <xsl:variable name="y" select="(( 100  to  200 ))[$xq:p2]"/>

in which is setting up the range variable $y which then isn't used in
(this) sort expression.

      <xsl:for-each select="$xq:here">
         <xsl:variable name="xq:index" select="for $i in string-to-codepoints(.) return($i - 32)"/>
         <xsl:variable name="xq:p1" select="$xq:index[1]"/>
         <xsl:variable name="x" select="(( 1  to  10 ))[$xq:p1]"/>
         <xsl:variable name="xq:p2" select="$xq:index[2]"/>
         <xsl:variable name="y" select="(( 100  to  200 ))[$xq:p2]"/>
         <xsl:sequence select="$x"/>


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:

More information about the talk mailing list