I'm trying to reassign a variable in xslt or attempt to do something similar.. I'm trying to loop through a series of product categories.. if the current product category is the one in the loop I want to assign it's position to a variable.. if there is no current category I'd like to assign the index to 0
What im trying to do is basically in jQuery tools.. if a category exists pass its index into the javascript so it sets that tab visible on page load..
While you can't reassign a variable explicitly (as in they are "variable by type, not value"), from your explanation, you should be able to do what you want here.
Variables in XSLT are defined by scope, so since you are within a for-each loop, the variable only has scope for that iteration - hence why you can "re-assign" it... like so:
Hi Lee thanks for your reply... the biggest problem is I need to use the variable outside of the for-each loop..
I ended up getting around it by assigning a var in javascript and then using that javascript var outside my loop in a javascript function call... which worked for this scenario.. id be keen to know how you'd make it work using straight xslt..
Reassign Variable
Hi Guys,
I'm trying to reassign a variable in xslt or attempt to do something similar.. I'm trying to loop through a series of product categories.. if the current product category is the one in the loop I want to assign it's position to a variable.. if there is no current category I'd like to assign the index to 0
What im trying to do is basically in jQuery tools.. if a category exists pass its index into the javascript so it sets that tab visible on page load..
<xsl:for-each select="$allProductCategories">
<xsl:variable name="currentCategoryIndex">
<xsl:if test="$currentProductCategoryID = @id">
<xsl:value-of select="position()"/>
</xsl:if>
</xsl:variable>
Hi Tom,
While you can't reassign a variable explicitly (as in they are "variable by type, not value"), from your explanation, you should be able to do what you want here.
Variables in XSLT are defined by scope, so since you are within a for-each loop, the variable only has scope for that iteration - hence why you can "re-assign" it... like so:
Cheers, Lee.
Hi Lee thanks for your reply... the biggest problem is I need to use the variable outside of the for-each loop..
I ended up getting around it by assigning a var in javascript and then using that javascript var outside my loop in a javascript function call... which worked for this scenario.. id be keen to know how you'd make it work using straight xslt..
is working on a reply...