Results 1 to 4 of 4

Thread: XML question, Round 2!!! - urgent

  1. #1

    Thread Starter
    Addicted Member DJ_Catboy's Avatar
    Join Date
    Jan 2003
    Location
    Suffolk, UK
    Posts
    159

    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

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    What part doesn't work? Are you getting an error? Do you get a value? Do you get the wrong value?
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Addicted Member DJ_Catboy's Avatar
    Join Date
    Jan 2003
    Location
    Suffolk, UK
    Posts
    159
    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

  4. #4
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    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
  •  



Click Here to Expand Forum to Full Width