Solved

How should I write this XPath statement

Posted on 2015-01-20
1
81 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 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 our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Powershell import xml to array (non-cli xml) 4 36
XSL - substring between 2 commas 12 25
Html split(text) 2 32
Java array 21 87
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
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.

726 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