I’m not sure how to explain this, so if there’s a better way please let me know.
I have a value that I need to search the XML For, but I want to search for another value before I get my result set.
Let me show you:
<n:TaskGetResponse>
<MemHead>
<memidnum>1262753194</memidnum>
<memrecno>22672100</memrecno>
</MemHead>
<MemHead>
<memidnum>1262753194</memidnum>
<memrecno>22672104</memrecno>
</MemHead>
<EntXtsk>
<caudrecno>6348855</caudrecno>
<memrecno>22672100</memrecno>
</EntXtsk>
<EntXtsk>
<caudrecno>6348855</caudrecno>
<memrecno>22672101</memrecno>
</EntXtsk>
<EntXtsk>
<caudrecno>6348878</caudrecno>
<memrecno>22672102</memrecno>
</EntXtsk>
<MemXtsk>
<caudrecno>6348878</caudrecno>
<memrecno>22672103</memrecno>
</MemXtsk>
</n:TaskGetResponse>
I have the memidnum of 1262753194. I want to find All EntXtsk and MemXtsk that have a memrecno that matches all MemHead’s that have a memidnum of 1262753194.
In this example I have 2 MemHeads that have the same memidnum, but different memrecno (there are 2 memrecno’s to look at). I want to find all *Xtsk that have a memrecno that match the 2.
Is this possible with XPath?
Using
TaskGetResponse/*[name(.) = 'MemXtsk' or name(.) = 'EntXtsk']
I can get all the *Xtsk nodes.
But not sure how to get the ones only associated with the memidnum->memrecno that I need.
Any help would rock.
Update:
I can run
TaskGetResponse/*[memrecno= //TaskGetResponse/*[memidnum="1262753194"]/memrecno]
And that gets me everything with that memrecno combination. But I’m not sure how to say only get me EntXtsk and MemXtsk.
Use:
This selects any element named
EntXtskorMemXtsk, that is a child of the top element of the XML document, and that has amemrecnochild, whose string value is equal to the string value of somememrecnoelement that is a child of aMemHeadelement that is a child of the top element in the XML document and that also has amemidnumchild whose string value is"1262753194"XSLT – based verification (I strongly recommend using the XPath Visualizer for any XPath exploration):
when applied on this XML document (the provided one with added one more
MemXtskelement at the end):evaluates the XPath expression and copies to the output the selected nodes: