Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to "zip" two lists together? #90

Open
jf-tech opened this issue May 11, 2023 · 1 comment
Open

How to "zip" two lists together? #90

jf-tech opened this issue May 11, 2023 · 1 comment

Comments

@jf-tech
Copy link
Contributor

jf-tech commented May 11, 2023

Say I have a doc like this:

<root>
   <NAMES>
     <name>Wang</name>
     <name>Joe</name>
     <name>Ali</name>
   </NAMES>
   <AGES>
     <age>10</age>
     <age>20</age>
     <age>17</age>
   </AGES>
</root>

I want to find out the age of a person whose name is Joe. So essentially I need to zip two lists <NAMES> and <AGES> together, based on position(). I can't figure out a way to write this query:

/root/AGES/age[ position() = ../../NAMES/name[text() = 'Joe']::position() ]

Basically I want to get an <age> node whose position() equals the position() of a <name> node whose value is Joe. I have a strong assumption and guarantee that the numbers of elements in the <NAMES> and <AGES> lists are the same, so no need to worry about that.

The query doesn't work, the error basically says: has an invalid token.

Any insight/idea how to achieve this? Would really like to avoid doing the zip processing in code.

Thanks!!

@zhengchun
Copy link
Contributor

/root/AGES/age[position() = ../../NAMES/name[text() = 'Joe']/position()] expr is correct that shoud be able to work in antoher languages but not in xpath package.

I mark it as bug or enhancement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants