This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: sorting nodes in reverse document order


Ann,

>I have a for-each statement inside a template that outputs a list of the
>ancestors of the current context node. I couldn't use the parent or
>ancestor axes to get this list because these nodes are not contained
>within their parent nodes in the XML source document.  Each node has a
>SUPERCLASS attribute whose value is the name of its parent.
[snip]
>How can I sort these nodes and output them in reverse order?

You can use xsl:sort within xsl:for-each for that, but I don't think that's
the easiest way of going about your problem.  As Mike Kay says "Don't
Iterate, Recurse" (p.551).

Assuming an input of a number of CLASS elements, this works:

<!-- define a key into the node NAMEs for efficiency -->
<xsl:key name="classes" match="CLASS" use="@NAME"/>

<xsl:template match="//CLASS[...]"><!-- insert predicate of choice -->
  <xsl:apply-templates select="." mode="hierarchy" />
</xsl:template>

<xsl:template match="CLASS" mode="hierarchy">
  <!-- do this template on my superclass -->
  <xsl:apply-templates select="key('classes', @SUPERCLASS)"
mode="hierarchy" />
  <!-- then print my details -->
  <br data="{@NAME} -- {@SUPERCLASS}">
    <a href="{@NAME}.html">
      <xsl:value-of select="@NAME"/>
    </a>
  </br>
</xsl:template>

Hope this helps,

Jeni


Dr Jeni Tennison
Epistemics Ltd, Strelley Hall, Nottingham, NG8 6PE
Telephone 0115 9061301 • Fax 0115 9061304 • Email
jeni.tennison@epistemics.co.uk



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]