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

alternative for modes

Subject: alternative for modes
From: "Peter Billen" <peter@xxxxxxxxxxx>
Date: Thu, 12 Feb 2004 11:10:48 +0100
xsl templates mode
Hello all,

I'm having a problem with doing something on a more proper way, I hope you
help me with this one.

Imagine you have a template which can be used on several places in your
stylesheet, let's call it 'generalTemplate'

<xsl:template name="generalTemplate>
	do some calculations here, but stay in current node context (so no
for-each, ... -  see below)
	<xsl:apply-templates>
		... 
	</xsl:apply-templates>
</xsl:templates>

Imagine this function can be called on a tag <root> and <child> is a child
of that tag. So each time when 'generalTemplate' is called, a template which
matches the tag 'child' will be called too:

<xsl:template match="child">
	...
</xsl:template>

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.

A nice way to accomplish would be this, but this doesn't work since mode
should be a qname, and not an xpath expression:

<xsl:template name="generalTemplate>
	<xsl:param name="p"/>
	<xsl:apply-templates mode="$p">
		...
	</xsl:apply-templates>
</xsl:templates>

<xsl:template match="child" mode="situation1">...</>
<xsl:template match="child" mode="situation2">...</>
...

Then I came up with the following:

<xsl:template name="generalTemplate>
	<xsl:param name="p"/>
	<xsl:apply-templates>
		<xsl:with-param name="p" select="$p"/>
		...
	</xsl:apply-templates>
</xsl:templates>

<xsl:template match="child">
	<xsl:if test="$p = 'situation1'>
		...
	<xsl:if test="$p = 'situation2'>
		...
	...
</xsl:template>

Actually, this works perfect, but I don't like it.

So my question is now: are there any other outcomes for this situation,
which do this on a more generic way?

Thanks for your time,

Peter


 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.