[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
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:choose> <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:otherwise>1,A;i</xsl:otherwise> </xsl:choose> </xsl:variable> <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 :)
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|