Solved

How should I write this XPath statement

Posted on 2015-01-20
1
74 Views
Last Modified: 2015-01-21
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
Comment
Question by:Anthony Lucia
1 Comment
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 40561420
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now