Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi
I try to calculation in XSLT
I have an XPathNodeIterator with values from a table
I get this XML in XSLT with
<xsl:variable name="test" select="GetTest:GetTest()//test" />
...
<xsl:for-each select="$test"> <xsl:call-template name="prizeTotal"> <xsl:with-param name="amount" select="./quantity"/> <xsl:with-param name="prize" select="./price"/> </xsl:call-template></xsl:for-each>
And now i want a total. I tried this with
<xsl:template name="prizeTotal"> <xsl:param name="amount"/> <xsl:param name="price"/>
<xsl:variable name="total" select="number($amount) * number($price)"/>
<xsl:value-of select='format-number($total, "#.00")' /></xsl:template>
but that gives for example that output:
80.0040.00 (80.00 is from the first node and 40.00 from the second node) how can i calculate 80.00 with 40.00 (total = 120.00)?
<xsl:for-each select="$test"> <xsl:variable name="total" select="quantity * price"/></xsl:for-each>
should work for xml like:
...<test> <quantity /> <price /></test>...
Thanks for your answer, but this not work for me :(
The output is yet: 80.0080.0040.0040.00
do you have and xml -file example?
Yes of course
<tests> <test id="2" nodeid="3"> <quantity>2</quantity> <price>20.0</price> ... </test> <test id="3" nodeid="3"> <quantity>10</quantity> <price>20.0</price> ... </test></tests>
Try this:
<xsl:variable name="test" select="GetTest:GetTest()//test" /><xsl:variable name="tmpTotal"> <total_amount> <xsl:for-each select="$test"> <item> <xsl:value-of select="./quantity * ./price"/> </item> </xsl:for-each> </total_amount></xsl:variable><xsl:variable name="myTotal" select="msxml:node-set($tmpTotal)"/><xsl:value-of select="sum($myTotal/total_amount/item)" />
Thanks Josh for your reply!
Your solution give me that output: 120.00120.00, okay it calculate perfect but it give me the value twice, how can i fix that?
Okay... <xsl:if test="position() = 1"> </xsl:if> do that, but I think this is not perfect?
DAMN! My failure... I had two <xsl:for-each>... SORRY! Thank Josh!
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
XSLT Calculation
Hi
I try to calculation in XSLT
I have an XPathNodeIterator with values from a table
I get this XML in XSLT with
And now i want a total. I tried this with
but that gives for example that output:
80.0040.00 (80.00 is from the first node and 40.00 from the second node) how can i calculate 80.00 with 40.00 (total = 120.00)?
should work for xml like:
Thanks for your answer, but this not work for me :(
The output is yet: 80.0080.0040.0040.00
do you have and xml -file example?
Yes of course
Try this:
Thanks Josh for your reply!
Your solution give me that output: 120.00120.00, okay it calculate perfect but it give me the value twice, how can i fix that?
Okay... <xsl:if test="position() = 1"> </xsl:if> do that, but I think this is not perfect?
DAMN! My failure... I had two <xsl:for-each>... SORRY! Thank Josh!
is working on a reply...