|
Subject: Re: sorting nodes in reverse document order From: Jeni Tennison <Jeni.Tennison@xxxxxxxxxxxxxxxx> Date: Mon, 15 May 2000 17:20:45 +0100 |
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@xxxxxxxxxxxxxxxx
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| sorting nodes in reverse document o, Ann Marie Rubin - Su | Thread | Re: sorting nodes in reverse docume, Ann Marie Rubin - Su |
| Re: feature request, David Carlisle | Date | FOP Sample Code, scott . wright |
| Month |