XPath Expression to calculate total amount for order details

Please support our XML, XSLT and XPATH advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2009
Posts: 3
Reputation: extkml is an unknown quantity at this point 
Solved Threads: 0
extkml extkml is offline Offline
Newbie Poster

XPath Expression to calculate total amount for order details

 
0
  #1
20 Days Ago
I have a xml file like this

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1.  
  2. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  3. <orders>
  4. <order orderDate="1/1/2009" orderNo="1">
  5. <customer id="nnghiem" name="nguyen nghiem"/>
  6. <item id="item-1" price="25000" quantity="0"/>
  7. <item id="item-2" price="22000" quantity="3"/>
  8. </order>
  9. <order orderDate="2/2/2009" orderNo="2">
  10. <customer id="lp" name="lampard"/>
  11. <item id="item-1" price="25000" quantity="2"/>
  12. <item id="item-2" price="22000" quantity="8"/>
  13. </order>
  14. <order orderDate="3/3/2007" orderNo="3">
  15. <customer id="nnghiem" name="nguyen nghiem"/>
  16. <item id="item-1" price="25000" quantity="7"/>
  17. <item id="item-2" price="22000" quantity="6"/>
  18. </order>
  19. </orders>

Now i want to calculate total amount for each order

this is my xsl file

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <xsl:for-each select="/orders/order">
  2. <tr>
  3. <td> <xsl:value-of select="@orderNo"></xsl:value-of> </td>
  4. <td> <xsl:value-of select="@orderDate"></xsl:value-of> </td>
  5. <td> <xsl:value-of select="customer/@name"></xsl:value-of> </td>
  6. <td> <xsl:value-of select="sum(item/@quantity * item/@price)"></xsl:value-of></td>
  7. </tr>
  8. </xsl:for-each>

When i transform xml+xsl => html, an error occured at the line
XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <xsl:value-of select="sum(item/@quantity * item/@price)"></xsl:value-of>

I can only guess that my xpath - expression is not correct, i also tried this:
XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <xsl:value-of select="sum(item/@quantity * @price)"></xsl:value-of>

But i also got the same problem. How can i fix this?

I need some advices, i've just learnt XSL for 1 week.

Thanks for your attention
Last edited by extkml; 20 Days Ago at 6:29 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,562
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 454
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven
 
0
  #2
19 Days Ago
Take a look at this thread.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC