Project

Profile

Help

Bug #5695

closed

Unexpected sort order in Firefox

Added by Martynas Jusevicius 2 months ago. Updated about 2 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
-
Sprint/Milestone:
Start date:
2022-09-26
Due date:
% Done:

100%

Estimated time:
Applies to JS Branch:
2, Trunk
Fix Committed on JS Branch:
Fixed in JS Release:
SEF Generated with:
Platforms:
Company:
-
Contact person:
-
Additional contact persons:
-

Description

The following stylesheet outputs B D A C E Z in Firefox and A B C D E Z in Chrome (tested on https://martin-honnen.github.io/xslt3fiddle/).

Not sure this has to do with collations, but I added one as suggested by Norm.

Note that there is one element without dct:title which might be part of the cause. After removing it, Firefox also returns A B C D E Z.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="3.0"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:dct="http://purl.org/dc/terms/"
  exclude-result-prefixes="#all"
  expand-text="yes">

  <xsl:output method="xml" indent="yes"/>
  <xsl:mode on-no-match="shallow-copy"/>

  <xsl:variable name="results" as="document-node()">
    <xsl:document>
      <rdf:RDF
          xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
          xmlns:j.0="http://purl.org/dc/terms/"> 
        <rdf:Description>
          <j.0:title>D</j.0:title>
        </rdf:Description>
        <rdf:Description>
          <j.0:title>B</j.0:title>
        </rdf:Description>
        <rdf:Description>
          <!-- no title -->
        </rdf:Description>
        <rdf:Description>
          <j.0:title>C</j.0:title>
        </rdf:Description>
        <rdf:Description>
          <j.0:title>Z</j.0:title>
        </rdf:Description>
        <rdf:Description>
          <j.0:title>A</j.0:title>
        </rdf:Description>
        <rdf:Description>
          <j.0:title>E</j.0:title>
        </rdf:Description>
      </rdf:RDF>
    </xsl:document>
  </xsl:variable>

  <xsl:template match="/" name="xsl:initial-template">
    <xsl:variable name="sorted-results" as="document-node()">
      <xsl:document>
        <xsl:for-each select="$results/rdf:RDF">
            <xsl:copy>
                <xsl:perform-sort select="*">
                    <xsl:sort select="dct:title" order="ascending" collation="http://www.w3.org/2005/xpath-functions/collation/codepoint"/>
                </xsl:perform-sort>
            </xsl:copy>
        </xsl:for-each>
      </xsl:document>
    </xsl:variable>
    
    <xsl:value-of select="$sorted-results/rdf:RDF/*/dct:title"/>
  </xsl:template>
  
</xsl:stylesheet>
Actions #1

Updated by Norm Tovey-Walsh 2 months ago

  • Status changed from New to Resolved
  • Sprint/Milestone set to SaxonJS 2.5
  • Applies to JS Branch Trunk added

I discovered that Compare.js was not handling null sort values in a consistent way. Given a and b, if a was null and b was not, it returned -1 for the comparison. But if a was not null and b was, it didn't return 1, it just continued. That meant the result was dependent on the underlying sort order in the browser. Turns out, Chrome and Firefox do it differently!

Actions #2

Updated by Norm Tovey-Walsh about 2 months ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in JS Release set to SaxonJS 2.5

Fixed in SaxonJS 2.5.

Please register to edit this issue

Also available in: Atom PDF Tracking page