Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

How to get Index of parent node of a child node

Options
Parasofttoudaya
Parasofttoudaya Posts: 232 ✭✭

Hi Team,

I am trying to get the parents for each child

for $item in (/root/Json[1]/item[]/employee[1]/item[])
return
/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)

Comments

  • benken_parasoft
    benken_parasoft Posts: 1,232 ✭✭✭
    Options

    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.