XPath question

?

---

I've got a data schema which represents an xml document like:
....
<purchases>
<purchase>
<category></category>
<item></item>
<price></price>
</purchase>
</purchases>
....

There can be an unlimited number of purchases.

I'd like to create a repeating table which lists all the categories
and sums up the prices. Something similar to the SQL statement:
Select category, sum(price) from purchases group by category.

Is this possible with my existing schema?

I've though about adding another repeating element:
<category_name></category_name>

And adding categories as purchase/category is modifed, then I can
create a repeating table of category_name, with an expression box to
sum up the totals. This is where the problem came up. With a schema
like I've shown, I can't seem to get what I want. I tried an XPath
expression like sum(../../purchase[category=category_name]/price), but
infopath complains that purchase/category_name cannot be found. It
appears that items referenced in the []'s are relative to purchase?
instead of the initial context of the xpath. Can anyone help?
 
?

---

category_name can't be found because it's not there. It's looking for it to be a sibling to category the way you wrote your XPath. You need to give it a more explicit pointer to the location of that field.
That's the problem I'm having, how do I explicitly reference the
initial category_name? The context for the XPath expression starts
with the category_name node, I then back up the tree and descend into
the purchase node. How do I refer to the original node?
As for the list you want... you will need to have a repeating section bound to purchase, but filtered to only show a unique list of categories. Then it would should the category name, and do the sum like you are trying to figure out.

How do I specify a unique filter? The only filter options I seem to
have available are XPath expressions, and I have no idea how to
express uniqueness with XPath.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top