[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: sorting nodes in reverse document order

Subject: Re: sorting nodes in reverse document order
From: Ann Marie Rubin - Sun PC Networking Engineering <Annmarie.Rubin@xxxxxxxxxxxx>
Date: Tue, 16 May 2000 12:24:31 -0400 (EDT)
xsl for each reverse
Jeni,

Thanks for your suggestions.  The <xsl:template match="CLASS" mode="hierarchy"> 
rule that you suggested seems to select the parent (@SUPERCLASS) of each class 
element in the XML source tree.  

What I want to do is match each CLASS, output some CLASS data, then print the 
ancestors for the matched class (not all classes in the hierarchy). The 
following code does output the ancestors for each class, but in document order.  
I need to output the ancestors in reverse document order.

<xsl:sort> does not work because I'm calling the hierarchy template recursively 
to generate the list of ancestors. Each time the hierarchy template is 
processed, it returns a single node, because each class has only one parent.  
Therefore, there is no node list to sort.  

I was trying to think of a way to save each node in a variable and then output 
the variables in reverse order, but haven't figured out how to do it or if it 
would work at all.

This works to output ancestors in document order:

<xsl:template match="CLASS">
 ...
 outputs some class data
 ...
 
<h2>Class Hierarchy</h2>
<!-- Call hierarchy template to output ancestors of this class -->
<xsl:call-template name="hierarchy"/>


<!-- named template to do the hierarchy tracing -->
<xsl:template name="hierarchy">
<br data="{@NAME} -- {@SUPERCLASS}"><a href="{@NAME}.html"><xsl:value-of
select="@NAME"/></a></br>
<xsl:if test="@SUPERCLASS">
  <xsl:param name="parentname" select="@SUPERCLASS"/>
  <xsl:for-each select="//CLASS[@NAME=$parentname]">
       <xsl:call-template name="hierarchy"/>
  </xsl:for-each>
</xsl:if>
</xsl:template>


Ann Marie

	X-Sender: JTennison@NTServer
	To: Annmarie.Rubin@xxxxxxxxxxxx
	From: Jeni Tennison <Jeni.Tennison@xxxxxxxxxxxxxxxx>
	Subject: Re: sorting nodes in reverse document order
	Cc: xsl-list@xxxxxxxxxxxxxxxx
	Mime-Version: 1.0
	X-MDaemon-Deliver-To: Annmarie.Rubin@xxxxxxxxxxxx
	Content-Transfer-Encoding: 8bit
	X-MIME-Autoconverted: from quoted-printable to 8bit by 
purol.East.Sun.COM id MAA16508
	
	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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.