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

RE: alternative for modes

Subject: RE: alternative for modes
From: "Jim Fuller" <jim.fuller@xxxxxxxxxxxxxx>
Date: Fri, 13 Feb 2004 00:29:07 -0000
streetrace cars
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Peter Billen
> Sent: 12 February 2004 22:32
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE:  alternative for modes
> 
> 
> Oki I think it's time for an example :) Imagine:
> 
> <streetrace>
> 	<car>
> 		<owner>...</owner>
> 		...
> 	</car>
> 	<car>
> 		<owner>...</owner>
> 		...
> 	</car>
> 	...
> </streetrace>
> 
> Now imagine you want to print out all the cars of the 
> streetrace: first all in red, then in blue, sorted by the 
> owner of the car(in my example of course, everything is a bit 
> more complicated, especially the sorting code). The best I 
> came up with, is the following:
> 
> <xsl:template match="streetrace>
> 	<!-- print cars in blue !-->
> 	<xsl:call-template name="giveCarsSorted">
> 		<xsl:with-param name="mode" select="'blue'"/>
> 	</xsl:call-template>
> 	<!-- in red !-->
> 	<xsl:call-template name="giveCarsSorted">
> 		<xsl:with-param name="mode" select="'red'"/>
> 	</xsl:call-template>
> </xsl:template>
> 
> <xsl:template name="giveCarsSorted">
> 	<xsl:param name="mode"/>
> 
> 	<xsl:apply-templates> // this will go to each <car>-element
> 		<xsl:sort select="car/owner"/> // sort on 
> <owner> in <car>
> 		<xsl:with-param name="mode" select="$mode"/> // 
> propagate $mode
> 	</xsl:apply-templates>
> </xsl:template>
> 
> <xsl:template match="car">
> 	<xsl:param name="mode"/>
> 
> 	<xsl:if test="$mode = 'blue'">
> 		<font color="blue"><xsl:value-of 
> select="."/></font><br/>
> 	</xsl:if>
> 	<xsl:if test="$mode = 'red'">
> 		<font color="red"><xsl:value-of select="."/></font><br/>
> 	</xsl:if>
> </xsl:template>
> 
> I hope I didn't make any big mistakes, since I haven't tested 
> it myself.

Why are you mixing the sorting and the fact that you want blue or red ?

There are many ways of solving this problem w/o modes, perhaps you could
use a top level nested xsl:variable to sort the data first

<xsl:variable name="data-sorted-by-owner">
	<xsl:apply-templates select="//car">
          <xsl:sort select="car/owner"/>
	</xsl:apply-templates>
</xsl:variable>

<xsl:variable name="data-sorted-by-car">
	<xsl:apply-templates select="//car">
          <xsl:sort select="car"/>
	</xsl:apply-templates>
</xsl:variable>

Then refer to $data-sorted-by-car or $data-sorted-by-owner.

Use a simple match template for this and create multiple variables for
whatever sorting your want...then use a named template for the color. At
worst this solution may require you to use processor specific node-set
function.

Gl, jim fuller


 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.