Skip to content

How to "zip" two lists together? #90

Description

@jf-tech

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!!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions