RE: [xsl] can a value of a parameter depends on a other value

Subject: RE: [xsl] can a value of a parameter depends on a other value
From: Roelof Wobben <rwobben@xxxxxxxxxxx>
Date: Fri, 2 Dec 2011 08:02:14 +0000
Thanks,

Bumping into a problem.



Im testing this script :



<xsl:param name="page" />
<xsl:variable name="hmm">
<xsl:choose>
<xsl:when test="$page='1'">number(1+$page*2)</xsl:when>
<xsl:otherwise>1+$page*2</xsl:otherwise>
</xsl:choose>
</xsl:variable>



before Im going to test Brandon scripts.



I was hoping I do this:



I have a month of 4 articles and I have 2 articles a page.  So there will be 2
pages.

Now I have to make 1 rule for every page.

I was hoping I could do this in 1 rule but it seems that the variable hmm is a
string instead of a number.

And converting it with number would not help.



Is there a way out. If not, then I have to make for every page a seperate when
and the website will contain some 80 when then.



Roelof




----------------------------------------
> Date: Thu, 1 Dec 2011 18:58:01 -0500
> From: brandon.ibach@xxxxxxxxxxxxxxxxxxx
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] can a value of a parameter depends on a other value
>
> 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 :)

Current Thread