Here is my scenario: I'm working on an e-commerce site built in Sharepoint 2010. I'm making a product catalog powered by a List, and styled by an XSLT stylesheet.
The (current) problem: Certain products have promotions from time to time. I have a field in my list with the text of the promotion, plus a checkmark (yes/no) if it's on promotion. If it is, my stylesheet will display that promotion text-otherwise it'll just have the product as normal.
What I need however is a dynamic way to add a superscript number like 1 to the end of the promotion text. This is for disclaimer purposes.
On a page only containing products on promotion, this is easy enough: I just use the position() function, wrapped by <sup></sup>
to increment by 1.
Here is part of my code, starting the loop:
<div>
<xsl:for-each select="$Rows">
<xsl:call-template name="dvt_1.rowview" />
</xsl:for-each>
</div>
Then the template:
<xsl:template name="dvt_1.rowview">
<xsl:variable name="PromotionVar"><xsl:value-of select="@OnPromotion"/> </xsl:variable>
Then testing for the promotion:
<xsl:if test="$PromotionVar='Yes'">
<p class="text-red">Promotion: <xsl:value-of select="@PromotionText1" disable-output-escaping="yes"/>
<sup>
<xsl:variable name="i" select="position()" />
<xsl:copy>
<xsl:value-of select="$i"/>
</xsl:copy>
</sup>
</p>
</xsl:if>
</xsl:template>
However on pages that have products that are not on promotion, this doesn't work as position() is based on all matched records.
Now if this were another scripting language like Javascript, I could just assign a variable and increment it in an if statement.. but from searching on Stackoverflow, I understand that XSLT is a functional language, and variables are actually immutable... so how should I approach this?
Here is another answer that may have what I need.. or not. It's all a bit complicated.
In XSLT how do I increment a global variable from a different scope?
Does anyone know how I should approach this? Thanks.