0

If I have two NodeLists where one list is a subset of the other, is there a way I can compare the lists to determine the position within the full NodeList of all the nodes in the subset NodeList? For example, given the following XML:

<Bill domain="QBO" sparse="false"> <Line> <AccountBasedExpenseLineDetail> 1 </AccountBasedExpenseLineDetail> </Line> </Bill> <Bill domain="QBO" sparse="false"> <Id>148</Id> <Line> <AccountBasedExpenseLineDetail> 1 </AccountBasedExpenseLineDetail> </Line> </Bill> 

Evaluating Bill/Line would return a NodeList with two nodes. Bill[Id]/Linewould return a NodeList with one node. How can I find the position of the single Node from the second NodeListwithin the first NodeList?

1 Answer 1

1

This XPath,

count((//Bill[Id])[1]/preceding-sibling::Bill[Line]) 

will start at the first Bill element in the document with an Id child element ((//Bill[Id])[1]) and count the number of preceding sibling Bill elements that have Line child element.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.