Hi

I want to sort a nodeset using xsl:sort and am finding that the nodeset will be 
sorted if there is an enclosing element but not if there isn't.

In an attempt to clarify, please look at the following example.  Incidentally, 
it doesn't make any difference if I build the nodeset on the fly as I have done 
here or take it from an input file.

I can't understand why sort 1 doesn't work but sort 2 does.  Can anybody 
clarify?  Thanks, Graeme

  <xsl:template name="sort-test">
    <!-- some elements that I want to output in order -->
    <xsl:variable name="elements-to-sort">
      <element>quick</element>
      <element>brown</element>
      <element>fox</element>
      <element>lazy</element>
      <element>dog</element>
    </xsl:variable>

    <!-- wrap those elements in an enclosing "words" element -->
    <xsl:variable name="enclosed-elements-to-sort">
      <words>
        <xsl:copy-of select="$elements-to-sort" />
      </words>
    </xsl:variable>

    <!-- sort 1- this does not sort the elements but outputs them in their 
original order -->
    <xsl:apply-templates select="xalan:nodeset($elements-to-sort)">
      <xsl:sort select="." />
    </xsl:apply-templates>

    <xsl:apply-templates select="xalan:nodeset($enclosed-elements-to-sort)" 
mode="sort" />
  </xsl:template>

  <!-- sort 2- this template successfully sorts the elements -->
  <xsl:template match="words" mode="sort">
    <!-- what is the difference between the effect of the call
         to apply-templates here and the one that doesn't work? -->
    <xsl:apply-templates>
      <xsl:sort select="." />
    </xsl:apply-templates>
  </xsl:template>


--

This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient (or have received this e-mail in error) please 
notify the sender immediately and destroy this e-mail. Any unauthorized 
copying, disclosure or distribution of the material in this e-mail is strictly 
forbidden.


Reply via email to