Xslt + JavaScript + foreach
This is an open discussion with 1 reply, filed under General.
Search
Not sure if its correct but i kinda create the function....
Corrections are welcome :)
<script language="JavaScript"> function price_<xsl:value-of select="position()"/> (quantity) { <xsl:for-each select="base-price-values/key"> <xsl:variable name="base-price-key-details" select="@name" /> <xsl:variable name="base-price-details" select="value" /> <xsl:variable name="start" select="substring-before($base-price-key-details, '-')" /> <xsl:variable name="end" select="substring-after($base-price-key-details, '-')" /> <!-- Create the between bags range --> <xsl:if test="position() != last()" > <![CDATA[if (quantity >= ]]> <xsl:value-of select="$start"/> <![CDATA[ && quantity <= ]]> <xsl:value-of select="$end"/> <![CDATA[) { price = ']]><xsl:value-of select="$base-price-details" /><![CDATA['; } ]]> </xsl:if> <!-- Create a last iof for the last node. --> <xsl:if test="position() = last()" > <![CDATA[if (quantity >= ]]> <xsl:value-of name="base-price-key-details" select="@name" /> <![CDATA[) { price = ']]><xsl:value-of select="$base-price-details" /><![CDATA['; } ]]> </xsl:if> </xsl:for-each> quantityPrice = price * quantity; document.getElementById('qty_price_<xsl:value-of select="position()"/>').innerHTML = "$" + parseFloat(quantityPrice.toFixed(2)); }
Create an account or sign in to comment.
Hey guys,
I am new to xslt and i am trying to figure out how to do something like that:
I've got a xml which i am using the Meta Keys extensions to use pair - value:
So my product has a price range which will be: - 1 - 9 cost will be $12.36 - 10 - 19 cost will be $11.10 - and 20+ will be $10
I am trying to build a javascript on the fly something like:
Anyone have any idea how to build that?
Cheers for all the helps.
Andre.