How to get Index of parent node of a child node

ParasofttoudayaParasofttoudaya Posts: 232 ✭✭

Hi Team,

I am trying to get the parents for each child

for $item in (/root/Json[1]/item[]/employee[1]/item[])
/root/Json[1]/item[ - - - - ]/manager[1]/text()

This for loop runs thru for all employees
where i need to get the managers of each employee. (if there is more employees under one manager, it supposed to return more than once)


  • benken_parasoftbenken_parasoft Posts: 890 ✭✭✭

    An XPath like that can be used to return a node list with multiple items. Generally you do something like that when using a Data Bank to populate a Writable Data Source. So, I assume you are doing something like what was described in this earlier post or this other one.

    In XPath, there is a function called "position()" that returns the 1-based index of a node. You can also refer to a node's parent using ".." in an XPath. Hopefully this helps point you in the right direction. Otherwise, for your particular case, it is hard to say exactly what your XPath should look like without having a sample message.

Sign In or Register to comment.