Project

Profile

Help

Bug #5545

closed

Why does @data-type on xsl:sort claim only text and number are supported?

Added by Norm Tovey-Walsh almost 2 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Documentation
Sprint/Milestone:
-
Start date:
2022-05-27
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
10, 11, trunk
Fix Committed on Branch:
11, trunk
Fixed in Maintenance Release:
Platforms:

Description

Consider:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                exclude-result-prefixes="xs"
                version="3.0">

<xsl:output method="text" encoding="utf-8"/>

<xsl:template match="/">
  <xsl:variable name="fred">
    <xsl:perform-sort select="('3', '2', '1', '5')">
      <xsl:sort data-type="xs:integer"/>
    </xsl:perform-sort>
  </xsl:variable>
  <xsl:sequence select="$fred"/>
</xsl:template>

</xsl:stylesheet>

And the description of data-type on xsl:sort:

data-type? { "text" | "number" | eqname } Determines whether collating is based on alphabetic sequence or numeric sequence. The permitted values are either text or number, or a built-in type in XML Schema, such as xs:date or xs:decimal.

Saxon 9 and 11 both say:

Warning at char 1 in xsl:perform-sort/@select on line 11 column 53 of out.xsl:
  SXWN9000: Evaluation will always throw a dynamic error: data-type on xsl:sort must be
  'text' or 'number'

What obvious mistake have I made?

Actions #2

Updated by Michael Kay almost 2 years ago

This is what the W3C spec says:

For backwards compatibility with XSLT 1.0, the data-type attribute remains available. If this has the effective value text, the atomized sort key values are converted to strings before being compared. If it has the effective value number, the atomized sort key values are converted to doubles before being compared. The conversion is done by using the stringFO30 or numberFO30 function as appropriate. If the data-type attribute has any other effective value, then this value must be an EQName denoting an expanded QName with a non-absent namespace, and the effect of the attribute is implementation-defined.

Actions #3

Updated by Martin Honnen almost 2 years ago

The current Saxon documentation on XSLT 3.0 compliance in https://www.saxonica.com/documentation11/index.html#!conformance/xslt30 states:

If the data-type attribute of the xsl:sort element has a value other than text or number, the effect is implementation-defined. (See 13.1.2 Comparing Sort Key Values) ► No additional values are recognised.

The only change to perhaps have disabled some qnames/XSD datatype seems to be long in the past before XSLT 2.0 became a spec, https://www.saxonica.com/documentation11/index.html#!changes/xslt20/7.3.1-7.4 says

Sorting using xsl:sort: I have changed the way data types are specified (in anticipation of changes to the W3C specification). The data-type attribute may now take values text or number only. The values text and number convert the actual sort key to xs:string or xs:double respectively before doing the comparison. If the data-type attribute is omitted there is no conversion. Values are then compared as supplied; if they are not comparable, a run-time error occurs. If you want to force conversion to a type such as xs:dateTime, use a casting function within the select expression, for example <xsl:sort select="xs:date(@birth-date)"/>

Could the 7.3 documentation have survived until now to say for data-type on xsl:sort "Determines whether collating is based on alphabetic sequence or numeric sequence. The permitted values are either text or number, or a built-in type in XML Schema, such as xs:date or xs:decimal"?

Actions #4

Updated by Michael Kay almost 2 years ago

Yes, the documentation for @data-type at https://www.saxonica.com/documentation11/index.html#!xsl-elements/sort is incorrect.

On the same page, the reference to an "internal sort routine" is also out of date. Saxon these days uses the JDK Arrays.sort().

Actions #5

Updated by Michael Kay almost 2 years ago

  • Category set to Documentation
  • Status changed from New to Resolved
  • Assignee set to Michael Kay
  • Priority changed from Low to Normal
  • Applies to branch 10, 11, trunk added
  • Fix Committed on Branch 11, trunk added

I have updated the documentation on the 11.x and 12.x branches (specifically, the "XSLT elements"/xsl:sort documentation) to bring it up to date.

Values of data-type other than "text" and "number" are not supported. The attribute is not needed post XSLT 1.0 because the select attribute can cast the sort key to the required type.

Actions #6

Updated by Debbie Lockett almost 2 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100

Saxon 11 documentation updated online.

Please register to edit this issue

Also available in: Atom PDF