[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 96
  • Last Modified:

How should I write this XPath statement

How would I write an XPath statement,executed from the 'Order' level to access the following:

+ Order
  + item
    - price
    - quantity
    - type

Open in new window


I wrote the following, but since I am executing this from the
Orders level, it seems to get confused on the Cardinality.  
How should I write this ?

fn:sum($Orders/item[type = 'Shoe']/quantity*price)

Open in new window


Thanks
0
Anthony Lucia
Asked:
Anthony Lucia
1 Solution
 
Geert BormansCommented:
Do you try to make a total of quantity * price for each shoe item?
You can't do that this way
Using XPath1/XSLT1 sum() only works on nodes, not on sequences... you will need recursive processing for that (I can show you an example if you send a decent example document and the XSLT you already have)
If you are using XSLT2, you need to make sure that also the price is in context
I would make a function fun:line-total() (note you need your own namespace)
fn:sum($Orders/item[type = 'Shoe']/fun:line-total(quantity,price))
if you are just using XPath 2.0 outside the context of XSLT
fn:sum(for $i in $Orders/item[type = 'Shoe'] return $i/quantity * $i/price)

Cheers
Geert
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now