<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		xmlns:xf="http://nwalsh.com/xmlns/xslt20/extension/functions"
		xmlns:xs="http://www.w3.org/2001/XMLSchema"
		xmlns:saxon="http://saxon.sf.net/"
		version="2.0">

  <xsl:output method="text"/>

  <saxon:collation name="unicode"
		   class="net.sf.saxon.sort.CodepointCollator"
		   default="yes"/>

  <saxon:collation name="english"
		   lang="en-US"
		   strength="primary"/>

  <saxon:collation name="french"
		   lang="fr-FR"
		   strength="tertiary"/>

  <saxon:collation name="german"
		   lang="de-DE"/>
		   
  <xsl:variable name="wordlist">
    <word>Agawam</word>
    <word>Ápres</word>
    <word>Ælfred</word>
    <word>Àbcdefg</word>
    <word>Pêche</word>
    <word>Péché</word>
    <word>Straße</word>
    <word>Strasse</word>
    <word>Strase</word>
  </xsl:variable>

  <xsl:template match="/">
    <xsl:text>Unicode code point collation:&#10;</xsl:text>
    <xsl:for-each select="$wordlist//word">
      <xsl:sort select="." order="ascending" data-type="text"
		collation="unicode"/>
      <xsl:text>  </xsl:text>
      <xsl:value-of select="."/>
      <xsl:text>&#10;</xsl:text>
    </xsl:for-each>

    <xsl:text>&#10;</xsl:text>
    <xsl:text>US English collation:&#10;</xsl:text>
    <xsl:for-each select="$wordlist//word">
      <xsl:sort select="." order="ascending" data-type="text"
		collation="english"/>
      <xsl:text>  </xsl:text>
      <xsl:value-of select="."/>
      <xsl:text>&#10;</xsl:text>
    </xsl:for-each>

    <xsl:text>&#10;</xsl:text>
    <xsl:text>French (France) collation:&#10;</xsl:text>
    <xsl:for-each select="$wordlist//word">
      <xsl:sort select="." order="ascending" data-type="text"
		collation="french"/>
      <xsl:text>  </xsl:text>
      <xsl:value-of select="."/>
      <xsl:text>&#10;</xsl:text>
    </xsl:for-each>

    <xsl:text>&#10;</xsl:text>
    <xsl:text>German (Germany) collation:&#10;</xsl:text>
    <xsl:for-each select="$wordlist//word">
      <xsl:sort select="." order="ascending" data-type="text"
		collation="german"/>
      <xsl:text>  </xsl:text>
      <xsl:value-of select="."/>
      <xsl:text>&#10;</xsl:text>
    </xsl:for-each>

    <xsl:text>&#10;</xsl:text>

    <xsl:for-each select="('unicode', 'english', 'french', 'german')">
      <xsl:call-template name="compare">
	<xsl:with-param name="word1" select="'Pêche'"/>
	<xsl:with-param name="word2" select="'Péché'"/>
	<xsl:with-param name="language" select="."/>
      </xsl:call-template>
    </xsl:for-each>

    <xsl:for-each select="('unicode', 'english', 'french', 'german')">
      <xsl:call-template name="compare">
	<xsl:with-param name="word1" select="'Strasse'"/>
	<xsl:with-param name="word2" select="'Straße'"/>
	<xsl:with-param name="language" select="."/>
      </xsl:call-template>
    </xsl:for-each>

    <xsl:for-each select="('unicode', 'english', 'french', 'german')">
      <xsl:call-template name="compare">
	<xsl:with-param name="word1" select="'Strase'"/>
	<xsl:with-param name="word2" select="'Straße'"/>
	<xsl:with-param name="language" select="."/>
      </xsl:call-template>
    </xsl:for-each>
  </xsl:template>

  <xsl:template name="compare">
    <xsl:param name="word1" as="xs:string"/>
    <xsl:param name="word2" as="xs:string"/>
    <xsl:param name="language" as="xs:string"/>

    <xsl:if test="compare($word1, $word2, $language) = 0">
      <xsl:text>"</xsl:text>
      <xsl:value-of select="$word1"/>
      <xsl:text>"</xsl:text>
      <xsl:text> and </xsl:text>
      <xsl:text>"</xsl:text>
      <xsl:value-of select="$word2"/>
      <xsl:text>"</xsl:text>
      <xsl:text> are the same in </xsl:text>
      <xsl:value-of select="$language"/>
      <xsl:text>&#10;</xsl:text>
    </xsl:if>
  </xsl:template>
    
  <xsl:function name="xf:compare">
    <xsl:param name="word1" as="xs:string"/>
    <xsl:param name="word2" as="xs:string"/>
    <xsl:param name="language" as="xs:string"/>

    <xsl:if test="compare($word1, $word2, $language) = 0">
      <xsl:text>"</xsl:text>
      <xsl:value-of select="$word1"/>
      <xsl:text>"</xsl:text>
      <xsl:text> and </xsl:text>
      <xsl:text>"</xsl:text>
      <xsl:value-of select="$word2"/>
      <xsl:text>"</xsl:text>
      <xsl:text> are the same in </xsl:text>
      <xsl:value-of select="$language"/>
      <xsl:text>&#10;</xsl:text>
    </xsl:if>
  </xsl:function>    

</xsl:stylesheet>
