Hiya,
I am finding that approaching XSLT with the same logic as I would PHP/ASP classic is leaving me a little flat.
Having been assisted with he > issue I was experiencing here
http://p2p.wrox.com/topic.asp?TOPIC_ID=74692
I have a new issue where my XSLT file works in Firefox but not in IE properly. The XSLT is like so and the xml is found in the linked topic above.
Code:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:param name="amount"/>
<xsl:param name="from"/>
<xsl:param name="to"/>
<xsl:param name="Domain"/>
<xsl:param name="remoteDomain"/>
<xsl:param name="UploadsFolder"/>
<xsl:template match="/currencies/currency">
<xsl:choose>
<xsl:when test="$from">
<xsl:choose>
<xsl:when test="$from='21'">
<xsl:if test="currencyID=$to">
<p class="calc">
<label class="currencyresultlabel">Result :</label>
<span><xsl:value-of select='format-number($amount * currencySellValue, "#.000")'/> <xsl:value-of select="currencyCountry"/></span>
<img class="flag">
<xsl:attribute name="src">
<xsl:value-of select="concat($remoteDomain, $UploadsFolder, currencyIcon)" />
</xsl:attribute>
</img>
<br />
<label class="currencyresultlabel"></label> 1 GBP = <xsl:value-of select="currencySellValue" /> <xsl:value-of select="currencyCountry" />
</p>
</xsl:if>
</xsl:when>
<xsl:when test="$from!='21'">
<xsl:if test="currencyID=$from">
<p class="calc">
<label class="currencyresultlabel">Result :</label>
<span><xsl:value-of select='format-number($amount div currencyBuyValue, "#.000")'/> GBP</span>
<img class="flag">
<xsl:attribute name="src">
<xsl:value-of select="concat($remoteDomain, $UploadsFolder, 'gb.gif')" />
</xsl:attribute>
</img>
<br /><label class="currencyresultlabel"></label><xsl:value-of select="currencyBuyValue" /><xsl:value-of select="currencyCountry" /> = 1 GBP
</p>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="/currencies/currencyComparison">
<xsl:choose>
<xsl:when test="$from='21' and $to='6'">
<xsl:variable name="No1Price" select="/currencies/currencyComparison[currencyNaming='Dollar' and currencyProvider='No1']/currencyRate"/>
<xsl:variable name="ThomasCookPrice" select="/currencies/currencyComparison[currencyNaming='Dollar' and currencyProvider='ThomasCook']/currencyRate"/>
<xsl:variable name="MSPrice" select="/currencies/currencyComparison[currencyNaming='Dollar' and currencyProvider='MS']/currencyRate"/>
<xsl:variable name="POPrice" select="/currencies/currencyComparison[currencyNaming='Dollar' and currencyProvider='PO']/currencyRate"/>
<xsl:variable name="threshold" select="0"/>
<xsl:variable name="numbers" select="/currencies/currencyComparison[currencyNaming='Dollar']/currencyRate" />
<xsl:variable name="minNumber" select="$numbers[not (. > $numbers)]" />
<xsl:variable name="No1_Value" select='format-number($amount * $No1Price, "#.000")' />
<xsl:variable name="Lowest_Value" select='$amount * $minNumber' />
<xsl:variable name="Lowest_Value_Name" select="/currencies/currencyComparison[currencyRate='$minNumber']/currencyProvider" />
<xsl:variable name="saving" select='format-number($No1_Value - $Lowest_Value, "#.000")' />
<xsl:choose>
<xsl:when test="$saving > $threshold">
<xsl:if test='$Lowest_Value_Name = "ThomasCook"'>
<p>You have gained #36;<xsl:value-of select='format-number($saving, "#.000")'/> </p>
<p>If you'd bought this at Thomas Cook, you would have received #36;<xsl:value-of select='format-number($Lowest_Value, "#.000")'/>! </p>
</xsl:if>
<xsl:if test='$Lowest_Value_Name = "PO"'>
<p>You have gained #36;<xsl:value-of select='format-number($saving, "#.000")'/> </p>
<p>If you'd bought this at The Post Office, you would have received #36;<xsl:value-of select='format-number($Lowest_Value, "#.000")'/>! </p>
</xsl:if>
<xsl:if test='$Lowest_Value_Name = "MS"'>
<p>You have gained #36;<xsl:value-of select='format-number($saving, "#.000")'/> </p>
<p>If you'd bought this at Marks and Spencers, you would have received #36;<xsl:value-of select='format-number($Lowest_Value, "#.000")'/>! </p>
</xsl:if>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
The problem starts in the second template match here: <xsl:template match="/currencies/currencyComparison">.
But the real issue seems to be with when I create the variables and try to use them as part of conditional logic straight after.
So say I set the variable saving here
Code:
<xsl:variable name="saving" select='format-number($No1_Value - $Lowest_Value, "#.000")' />
And I want to use the $saving variable for conditional logic like so:
Code:
<xsl:choose>
<xsl:when test="$saving > $threshold">
then do this
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
The if tests and logic with the choose above are never executed.
Similiarly, if I try to output $saving (right after after creating the variables) in IE I get an object required error.
Code:
<xsl:value-of select="$saving">
If you view this in FF the app works fine, if you view it in IE6 or IE7 only the first template match calculations are executed.
http://dev.cubeclients.com/Local-Aff...yconvertor.htm
Any ideas where I maybe going wrong?
Thanks in advance for your help!