Search

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:

<data>
    <base-price-values mode="normal">
        <key handle="1-9" name="1-9 ">
            <value handle="1236">12.36</value>
        </key>
        <key handle="10-19" name="10 - 19 ">
            <value handle="1110">11.10</value>
        </key>
        <key handle="20" name="20 + ">
            <value handle="10">10</value>
        </key>
    </base-price-values>
</data>

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:

&lt;script>
function price-product-{$position} (quantity) {
    if (quantity >= 1 &&  quantity <= 9) {
        price = '12.36';
    }
    if (quantity >= 10 &&  quantity <= 19) {
        price = '11.10';
    }
    if (quantity >= 20) {
        price = '10';
    }   
    quantityPrice = price * quantity;
    document.getElementById('qty_price_{$position}').innerHTML = "$" + parseFloat(quantityPrice.toFixed(2));    
}
&lt;script>

Anyone have any idea how to build that?

Cheers for all the helps.

Andre.

Not sure if its correct but i kinda create the function....

Corrections are welcome :)

&lt;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.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details