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

Re: can a value of a parameter depends on a other valu

Subject: Re: can a value of a parameter depends on a other value
From: Brandon Ibach <brandon.ibach@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 1 Dec 2011 18:58:01 -0500
Re:  can a value of a parameter depends on a other valu
On Thu, Dec 1, 2011 at 1:00 PM, Roelof Wobben <rwobben@xxxxxxxxxxx> wrote:
> One question. If I have two variables which depends on the same condition but will have other values do I have to write three seperate variable blocks ?

In a functional language, like XSLT, which disallows side-effects like
changing the value of a variable as execution proceeds, you can't use
a familiar pattern like "if (a = b) then set c = 1, d = 2, e = 3".
One pattern for accomplishing this is to set a temporary variable to a
composite value, then split it up.

This is easier and cleaner in XSLT 2.0, with support for sequences,
better string functions, etc.  However, it is still doable in XSLT 1.0
for reasonably simple cases.  I often find a little bit of ugliness
like this is worth the increase in maintainability gained by not
repeating the logic of the conditions.

<xsl:param name="page"/>

<xsl:variable name="labels">
        <xsl:when test="$page = 4">4,D;iv</xsl:when>
        <xsl:when test="$page = 3">3,C;iii</xsl:when>
        <xsl:when test="$page = 2">2,B;ii</xsl:when>
<xsl:variable name="arabic" select="substring-before($labels, ',')"/>
<xsl:variable name="alpha"
select="substring-before(substring-after($labels, ','), ';')"/>
<xsl:variable name="roman" select="substring-after($labels, ';')"/>

-Brandon :)

Current Thread


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.
First Name
Last Name
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.