?
Solved

How should I write this XPath statement

Posted on 2015-01-20
1
Medium Priority
?
88 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 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

Docker-Compose to Simplify Multi-Container Builds

Our veteran DevOps Author takes you through how to build a multi-container environment, managed with a single utility in order to simplify your deployments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month11 days, 2 hours left to enroll

770 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