Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing a variable in xml - pls help! ! ! ! 2

Status
Not open for further replies.

andrei22

Programmer
Aug 4, 2007
4
0
0
DE
i have tow for-each and one variable witch can be changed if some conditions are true, but after the finish of the for each the variable it is not any more recognized.


please read this code:

<xsl:for-each ....
<xsl:if ..contition1..
<xsl:variable name="var">1</xsl:variable>the variable can be changed here
</xsl:if>
......
<xsl:for-each ....
<xsl:if ..condition2..
<xsl:variable name="var">2</xsl:variable>but also here in the second for-each.
</xsl:if>
</xsl:for-each>
</xsl:for-each>

<xsl:choose>
<xsl:when test="$var=something"> ..... </xsl:when>here is the problem
<xsl:eek:therwise>
........
</xsl:eek:therwise>
</xsl:choose>

there is other solution to implement this? i think using variables will not work. pls help me!

thanks



 
As you declare and assign the variable in a for-each, you re-assign it multiple times. It is rather inpredictable what the value is going to be.

Apart from that, the variable is 'out of scope' outside the <xsl:if ...>.
The scope-problem can be solved like this:

<xsl:variable name="myvar">
<xls:choose>
<xsl:when test="...">1</xsl:when>
<xsl:when test="...">2</xsl:when>
<xsl:eek:therwise>0</xsl:eek:therwise>
</xsl:choose>
</xsl:variable>
...
<xsl:choose>
<xsl:when test="$myvar=1">...</xsl:when>
<xsl:when test="$myvar=2">...</xsl:when>
<xsl:eek:therwise>...</xsl:eek:therwise>
</xsl:choose>

Enjoy,
jel
 
the problem is that i need the for-each because the variable will be changed using the conditions that I obtain from the for-each loop. I think a solution can be by using recursion but i do not now how to use it in this case.
 
XSLT does not support assignment in the sense of most procedural languages.
I think a solution can be by using recursion but i do not now how to use it in this case.
Please describe the actual problem. Without that we cannot imagine a correct solution.

Tom Morrison
 
i do not now how to traverse all the nods of the tree using recursion, because in this way by using parameters the problem can be solved, because parameters can change their values. If you can tell me how to do this the problem is solved.

tanks

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top