Skip to content

Instantly share code, notes, and snippets.

@afreeland
Last active January 27, 2022 15:34
Show Gist options
  • Save afreeland/5532635 to your computer and use it in GitHub Desktop.
Save afreeland/5532635 to your computer and use it in GitHub Desktop.
XSLT: Set XSLT variable via choose
<xsl:variable name="Qty">
<xsl:choose>
<xsl:when test="Item_Item/Item_Locations/Item_Location[LocationID = $LocationID and ChannelID = $ChannelID]/Quantity = ''">
<xsl:text>0</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-before(Item_Item/Item_Locations/Item_Location[LocationID = $LocationID and ChannelID = $ChannelID]/Quantity,'.')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
@afreeland
Copy link
Author

I have always felt that variables are quite limited in XSLT. Once you set them, you cannot change them and
I was always trying to create a choose statement and set my variable to different values in the choose but you can’t do that because then the scope of the variable is only in that choose.

The way to do it is to not use the select attribute for setting the attribute but rather put the choose INSIDE the variable like Charles does here…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment