sorting differences xquery/xslt

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

sorting differences xquery/xslt

David Carlisle

Michael,

The following queries show different behaviour between sorting in xquery
and xslt in saxon 8.6.1. I've managed to confuse myself to the point
that I can't tell if this is as it should be (due to language
differences) or not, so I thought I'd ask here...

XQuery:

for $x in (0.0,-0.1)
 order by string($x) ascending
return string($x)

$ saxon8q t.xq
<?xml version="1.0" encoding="UTF-8"?>-0.1 0


An apparently similar XSLT expression produces the reverse ordering.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="2.0"
>
  <xsl:template name="main">
    <xsl:for-each select="(0.0,-0.1)">
      <xsl:sort order="ascending" select="string(.)"/>
      <xsl:sequence select="string(.)"/>
    </xsl:for-each>
  </xsl:template>
 
</xsl:stylesheet>


$ saxon8 -it main t.xsl
<?xml version="1.0" encoding="UTF-8"?>0 -0.1


Any insights gratefully received...

David
(test suite orderbylocal-59.xq)

________________________________________________________________________
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:
http://www.star.net.uk
________________________________________________________________________


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: sorting differences xquery/xslt

Michael Kay
The XQuery language spec states that there is one default collation for all
operations, including sorting, and the "default default" is Unicode
codepoint collation.

XSLT, for backwards compatibility reasons, uses Unicode codepoint collation
as the default for string comparison operations, but an
implementation-defined collation (in Saxon's case, the collation for the
current Java locale) for sorting. You can get XSLT to behave like XQuery by
specifying
collation="http://www.w3.org/2005/xpath-functions/collation/codepoint"; or
you could get XQuery to behave like XSLT by specifying

order by string ascending collation "http://saxon.sf.net/collation?lang=en"

I think that Java's default collation (for our locale) treats "-" as an
ignorable character, which is why "-0.1" collates after "0".

Michael Kay
http://www.saxonica.com/
 

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> David Carlisle
> Sent: 24 February 2006 01:21
> To: [hidden email]
> Subject: [saxon] sorting differences xquery/xslt
>
>
> Michael,
>
> The following queries show different behaviour between
> sorting in xquery
> and xslt in saxon 8.6.1. I've managed to confuse myself to the point
> that I can't tell if this is as it should be (due to language
> differences) or not, so I thought I'd ask here...
>
> XQuery:
>
> for $x in (0.0,-0.1)
>  order by string($x) ascending
> return string($x)
>
> $ saxon8q t.xq
> <?xml version="1.0" encoding="UTF-8"?>-0.1 0
>
>
> An apparently similar XSLT expression produces the reverse ordering.
>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>                 version="2.0"
> >
>   <xsl:template name="main">
>     <xsl:for-each select="(0.0,-0.1)">
>       <xsl:sort order="ascending" select="string(.)"/>
>       <xsl:sequence select="string(.)"/>
>     </xsl:for-each>
>   </xsl:template>
>  
> </xsl:stylesheet>
>
>
> $ saxon8 -it main t.xsl
> <?xml version="1.0" encoding="UTF-8"?>0 -0.1
>
>
> Any insights gratefully received...
>
> David
> (test suite orderbylocal-59.xq)
>
> ______________________________________________________________
> __________
> 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:
> http://www.star.net.uk
> ______________________________________________________________
> __________
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking
> scripting language
> that extends applications into web and mobile media. Attend
> the live webcast
> and join the prime developer group breaking into this new
> coding territory!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&
dat=121642
> _______________________________________________
> saxon-help mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re: sorting differences xquery/xslt

David Carlisle

Ah thanks, I thought it looked like a collation difference but couldn't
see where the differences were coming from (perhaps I should have waited
til the morning)

> You can get XSLT to behave like XQuery by

yo! one more test suite pass for xq2xsl:-)


David

________________________________________________________________________
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:
http://www.star.net.uk
________________________________________________________________________


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help