Subject: RE: [xsl] Variables From: Binerman <binerman@xxxxxxxxxxxxxxxxxxxxx> Date: Thu, 13 Feb 2003 01:43:08 -0600 |
Quoting Stevenson Ngila <Stevenson@xxxxxxxxxxxxxxxxxxxxxx>: > What i want to acheve is: > > if i have the following xml node i.e. > > <><><><><<><><><><><<><><><><<><><><><>< > <names option1="john" option2="peter"/> > <><><><><<><><><><><<><><><><<><><><><>< > > First of all check if the attribute "option1" exists(How do i do this?), > it's not a must it will be there. And if it does, > set the variable x = 400 - ( No.of option1 * 10 ) > > Given that the variable had been declared earlier. I'm new to xsl myself. The "given that the variable has been declared earlier" part confuses me too. But barring that requirement it would look something like this. Note that i sorta compensated for the part that confuses us by having x default to the starting value of 400 when @option1 is not present. If anyone knows the "real" way please enlighten. ;-) Assuming the <names> is the current context node: <xsl:variable name="x"> <xsl:when test="./@option1"> <xsl:value-of select="400 - (./@option1 * 10)"/> </xsl:when> <xsl:otherwise> <xsl:text>400</xsl:text> </xsl:otherwise> </xsl:variable> Additionally... i know that <xsl:text>400</xsl:text> works... but is this also valid? or does select always reference a node-set somehow? : <xsl:value-of select="400"/> > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of David > Carlisle > Sent: 12 February 2003 18:36 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: Re: [xsl] Variables > > > > How can i perform the following operation in xslt. > > <xsl:if test=@steve != 0> > x= x + 1 > </xsl:if> > > where x is a variable. > > if x = x + 1 then 0 = 1 and the world would be inconsistent. > this would be bad, so XSLT, like other declarative programing languages > doesn't let you change the value of a variable once it is bound. > > This is a FAQ. > > If you said what you were trying to generate rather than which illegal > operation you were trying to peform, someone could offer some further > help. > > David -- Ryan T. Gallagher XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Variables, Stevenson Ngila | Thread | Re: [xsl] Variables, David Carlisle |
RE: [xsl] Variables, Stevenson Ngila | Date | RE: [xsl] converting xsl-wd to xsl1, bryan |
Month |