[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: "Peter Billen" <peter@xxxxxxxxxxx>
Date: Thu, 12 Feb 2004 23:31:47 +0100
streetrace cars
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.

In my opinion the problem is: I need the same sorting more than once, so
it's a good idea to put it in a separate template (the sorting in my code is
a bit more complicated). However, all the situations where I need the
sorting, DO NOT depend on any specific value(s) of the <car>-element or one
or more of his children. So I THINK creating 'conditional templates' won't
help since there is no condition, which can be deduced from the
tree-structure, at all.

Thanks for your time,

Peter

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Wendell Piez
Sent: donderdag 12 februari 2004 20:27
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  alternative for modes

Peter,

I don't know what you mean by "calls the other template on a particular 
order" (maybe typo for "in a particular order"?), but it may still be 
possible to do as Jeni says, since you can bind the result of a template 
call to a variable and interrogate it, as in:

<xsl:variable name="general-result">
   <xsl:call-template name="general"/>
</xsl:variable>

...then depending on what general-result is, you can do one thing or 
another (as well as copying it to the output).

This is all wonderfully vague: maybe seeing a concrete example would help? 
It's surprising how often straight conditionals can be avoided in XSLT by 
the smart use of templates ... as in

<xsl:apply-templates select="child[$condition1]" mode="condition1"/>
<xsl:apply-templates select="child[$condition2]" mode="condition2"/>

... and such like. Which seems to be in line with what you're asking.

Cheers,
Wendell

At 09:35 AM 2/12/2004, you wrote:
>This is not possible I think, since the general template calls the other
>template on a particular order (based on the calculation in the general
>template), so I don't think it's possible in this situation.
>
>Thanks for the tip,
>
>Peter
>
>-----Original Message-----
>From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Jeni Tennison
>Sent: donderdag 12 februari 2004 12:41
>To: Peter Billen; xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>Subject: Re:  alternative for modes
>
>Hi Peter,
>
> > As I mentioned above, 'generalTemplate' can be called on several
> > places in the template, because everytime I need the same
> > calculations, ... on the 'root'-tag. But each time (in every other
> > place), I actually need different manipulations on the 'child'-tag.
>
>Just a thought, but depending on what the general template is doing,
>it might be that you can turn around the processing, so that instead
>of calling the general template with a parameter specifying the mode,
>you apply templates in the specific mode and those templates call the
>general template as appropriate to perform the necessary calculations.
>
>Cheers,
>
>Jeni


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
   Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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


 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.