944,209 Members | Top Members by Rank

Ad:
Nov 4th, 2009
0

XPath Expression to calculate total amount for order details

Expand Post »
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; Nov 4th, 2009 at 6:29 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
extkml is offline Offline
3 posts
since Nov 2009
Nov 5th, 2009
0
Re: XPath Expression to calculate total amount for order details
Take a look at this thread.
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in XML, XSLT and XPATH Forum Timeline: Convert XML file to another XML file using XSLT
Next Thread in XML, XSLT and XPATH Forum Timeline: How to Compare Date in XPath Expression





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC