Last post Jan 15, 2014 03:41 PM by StrangerInThisTown
Member
4 Points
39 Posts
Jan 10, 2014 02:11 PM|StrangerInThisTown|LINK
I need to be able to add together 3 items: <MRCTotal>, <NRCTotal> and <CODAmount> in XSL.. and display it
How do I do this? I thought it would be simple but I'm having a heck of a time.
Thanks in advance!
XML:
<Information> <MRC> <Service>Internet</Service> <Price>29.99</Price> </MRC> <MRC> <Service>TV</Service> <Price>19.99</Price> </MRC> <MRCTotal>49.98</MRCTotal> <NRC> <OTC>Installation</OTC> <Price>24.99</Price> </NRCServicesBlock> <NRCTotal>24.99</NRCTotal> <CODAmount>30.00</CODAmount> </Information>
XSL:
<font face="Arial,'Helvetica Neue',Helvetica,sans-serif" color="#444444" size="2" style="color:#444444; font-family:Arial,'Helvetica Neue',Helvetica,sans-serif; font-size:13px; line-height:14px; -webkit-text-size-adjust:none; font-weight:bold">Total: $<xsl:value-of select="//ExternalXML/WorkOrderInfo/NRCTotal"/> </font>
All-Star
15648 Points
2151 Posts
Jan 12, 2014 09:50 PM|Happy Chen - MSFT|LINK
hi StrangerInThisTown,
According to your descripttion, i would suggest you try to use <xsl:template match="/"> tag, as shown below:
<xsl:template match="/"> <xsl:apply-templates select="Feed"/> </xsl:template> <xsl:template name="sum"> <xsl:param name="nodes" /> <xsl:param name="sum" select="0" /> .. </xsl:template>
Please refer to the links below for more information:
Transforming XML using XSLT
http://stackoverflow.com/questions/3945054/transforming-xml-using-xslt
XSL - sum multiplication of elements
http://stackoverflow.com/questions/8551324/xsl-sum-multiplication-of-elements
Hope they can help you.
Jan 15, 2014 02:52 PM|StrangerInThisTown|LINK
Do you have an example of the code to use?
I can't change anything about the XML and one of the links suggests to do that and the other link is already what I'm doing, using XSL
thanks ahead of time!
Jan 15, 2014 03:32 PM|StrangerInThisTown|LINK
I ended up only needing to add 2 of them together, not 3. But either way, this code works:
<xsl:value-of select="sum(//Information/MRCTotal) + sum(//Information/NRCTotal) " />
But the result leaves me with 64.2599999999999
Now I need to know how to use my simple code above and round it
Jan 15, 2014 03:41 PM|StrangerInThisTown|LINK
GOT IT!
<xsl:value-of select="format-number(sum(//Information/MRCTotal) + sum(//Information/NRCTotal), '0.00') " />
Member
4 Points
39 Posts
How To Add/Sum 3 Different Items
Jan 10, 2014 02:11 PM|StrangerInThisTown|LINK
I need to be able to add together 3 items: <MRCTotal>, <NRCTotal> and <CODAmount> in XSL.. and display it
How do I do this? I thought it would be simple but I'm having a heck of a time.
Thanks in advance!
XML:
XSL:
All-Star
15648 Points
2151 Posts
Re: How To Add/Sum 3 Different Items
Jan 12, 2014 09:50 PM|Happy Chen - MSFT|LINK
hi StrangerInThisTown,
According to your descripttion, i would suggest you try to use <xsl:template match="/"> tag, as shown below:
Please refer to the links below for more information:
Transforming XML using XSLT
http://stackoverflow.com/questions/3945054/transforming-xml-using-xslt
XSL - sum multiplication of elements
http://stackoverflow.com/questions/8551324/xsl-sum-multiplication-of-elements
Hope they can help you.
Member
4 Points
39 Posts
Re: How To Add/Sum 3 Different Items
Jan 15, 2014 02:52 PM|StrangerInThisTown|LINK
Do you have an example of the code to use?
I can't change anything about the XML and one of the links suggests to do that and the other link is already what I'm doing, using XSL
thanks ahead of time!
Member
4 Points
39 Posts
Re: How To Add/Sum 3 Different Items
Jan 15, 2014 03:32 PM|StrangerInThisTown|LINK
I ended up only needing to add 2 of them together, not 3. But either way, this code works:
But the result leaves me with 64.2599999999999
Now I need to know how to use my simple code above and round it
Member
4 Points
39 Posts
Re: How To Add/Sum 3 Different Items
Jan 15, 2014 03:41 PM|StrangerInThisTown|LINK
GOT IT!