2
votes

I want to use collations in the Saxon based xslt transformation. The source file:

<root>
  <entry name="B" />
  <entry name="Aa" />
  <entry name="Ä" />
  <entry name="Az" />
</root>

and my transformation:

<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:saxon="http://saxon.sf.net/">
  <xsl:output indent="yes"/>

  <saxon:collation name="german" lang="de-DE"/>

    <xsl:template match="root">
      <root>
        <xsl:for-each select="entry">
          <xsl:sort select="@name" collation="german"/>
          <sorted entry="{@name}"/>
        </xsl:for-each>
      </root>
    </xsl:template>

</xsl:stylesheet>

This works almost fine in Oxygen, the output is:

<root xmlns:saxon="http://saxon.sf.net/">
   <sorted entry="Ä"/>
   <sorted entry="Aa"/>
   <sorted entry="Az"/>
   <sorted entry="B"/>
</root>

(The Ä should be the second entry, but that's another question, I guess)

But when I use the command line, I get an error:

java -jar saxon9he.jar -s:source.xml -o:out.xml -xsl:transformation.xsl


  XTDE1035: Collation file:/Users/<mypath>/german has not been defined
Failed to compile stylesheet. 1 error detected.

It looks as if saxon now wants to use german as a file. It does not exist.


The question is: how do I use this stylesheet on the command line.

If it is appropriate, I'd also ask how to get the "Ä" sorted between the two "A." entries, but I can ask this in another question.

1

1 Answers

3
votes

The simplest solution is not to use the collation attribute at all, but to use

<xsl:sort lang="de"/>

which asks the system to locate a collation suitable for German text, and is portable across XSLT processors.

If you do want a more precise collation, there is guidance on constructing Saxon collation URIs here: http://www.saxonica.com/documentation/extensibility/collation.xml

The reason for your error is that when the value you specify is a relative URI reference, it is interpreted as being relative to the base URI of the stylesheet. With Saxon, this will almost inevitably produce a collation URI that doesn't exist. It's not clear why the spec allows relative collation URIs; they could potentially be useful with some products, but they don't do anything useful with Saxon.