|
-
Feb 27th, 2003, 09:40 AM
#1
Thread Starter
Addicted Member
XML question, Round 2!!! - urgent
Hi,
OK. So my problem still stands but I have a new approach. Below is source XML...
Code:
<xml>
<data>
<value>1</value>
<item>200-500</item>
</data>
<data>
<value>2</value>
<item>300-100</item>
</data>
<data>
<value>3</value>
<item>450-151A</item>
</data>
</xml>
The result that I would like to see is as follows: -
Code:
<xml>
<data>
<total>6</total>
</data>
</xml>
So I want to add up the values in the "value" nodes. Does anybody know how to do this? I am now trying to use the sum() function as below: -
<xsl:value-of select="/xml/data[sum(value) > 0]">
this does not work....... please please help!!!
DJ
-
Mar 3rd, 2003, 05:47 PM
#2
What part doesn't work? Are you getting an error? Do you get a value? Do you get the wrong value?
-
Mar 4th, 2003, 03:30 AM
#3
Thread Starter
Addicted Member
Hi,
With regards to the above code example of mine, using the Sum doesn't return anything - however it can be tweaked so that it returns the following: -
<total>1200-5002300-1003450-151A</total>
It takes all nodes in the set that match the criteria - i want only the numbers - and for them to be added up!
Any help greatly received!
DJ
-
Mar 4th, 2003, 08:01 PM
#4
PowerPoster
Is this what you are looking for? This is just a quick and dirty example I wrote up, so if you have any questions, just let me know:
Source Xml
Code:
<cars>
<car make='Audi'>
<price>42000</price>
</car>
<car make='BMW'>
<price>47000</price>
</car>
<car make='Mercedes'>
<price>60000</price>
</car>
</cars>
Source Xsl
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="cars">
<b>Total Price:</b><hr/>
<xsl:value-of select="format-number(sum(car/price),'$0,000.00')" />
</xsl:template>
</xsl:stylesheet>
Basically, I match on the root node and sum up all the car node's price element values.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|