2 Replies - 755 Views - Last Post: 20 February 2013 - 07:00 PM

#1 sm1th  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 07-February 13

XPath question

Posted 20 February 2013 - 04:10 PM

Hi, I'm a beginner to the XML and Xpath languages, and I just have a relatively simple question.

XML:

<numbers>
  <number>33</number>
  <number>34.4</number>
  <number>33.8</number>
  <number>33.43</number>
  <number>34.46</number>
  <number>35</number>
  <number>33.49</number>
  <number>33.00</number>
</numbers>



Using Xpath I want to determine the sum of all the numbers which round off to 34. I am having trouble doing this. (The answer is 102.66.

Thanks in advance for your help!

Is This A Good Question/Topic? 0
  • +

Replies To: XPath question

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2875
  • View blog
  • Posts: 9,540
  • Joined: 12-December 12

Re: XPath question

Posted 20 February 2013 - 04:39 PM

Never used XPath but I would have a stab at:

sum(/numbers/number[round(.) = 34])

There is ceiling() or floor() depending on how you want to round (I haven't checked your arithmetic).
Was This Post Helpful? 1
  • +
  • -

#3 sm1th  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 07-February 13

Re: XPath question

Posted 20 February 2013 - 07:00 PM

Thank you very much Andrew. I have another question.

XML:

<products>
  <product id="1" name="Teekanne" price="25.00" category="1" />
  <product id="2" name="Bleistift" price="0.29" category="2" />
  <product id="3" name="Lautsprecher" price="19.00" category="2" />
  <product id="4" name="Tasse" price="1.99" category="1" />
  <product id="5" name="Apfelsaft" price="1.49" category="1" />
  <product id="6" name="CD-Rohling" price="0.89" category="2" />
  <category id="1" name="Sortiment 2005" />
  <category id="2" name="Sortiment 2006" />
</products>



Select the following product-siblings relatively from their current node.

(Desired output:)

    <product id="4" name="Tasse" price="1.99" category="1" />
    <product id="5" name="Apfelsaft" price="1.49" category="1" />
    <product id="6" name="CD-Rohling" price="0.89" category="2" />



I have this so far:

//product[3]/following-sibling::*

But that returns the category ones as well. I do not know how to specify @product.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1