I am attempting to merge two XML documents (using Pentaho Kettle), and I'm having trouble with my XPATH statement. In the first XML, I have a list of users and their user id's. In the second XML, I have a list of projects, each with an id that corresponds to the user working on it. I am trying to match the two based on the id's. The XPATH statement I'm using is as follows:

//users[user_id='?']/projects

I don't understand why this isn't working. The layout of the XML files is as follows:

<user name="UserOne" user_id="3"><projects/></user>
<user name="UserTwo" user_id="10"><projects/></user>
<project Y="1" name="ProjectOne" user_id="3" />
<project Y="7" name="ProjectTwo" user_id="3" />
<project Y="1" name="ProjectThree" user_id="10" />

The output that I'm looking for is:

<user name="UserOne" user_id="3">
   <projects>
      <project Y="1" name="ProjectOne" user_id="3" />
      <project Y="7" name="ProjectTwo" user_id="3" />
   </projects>
</user>
<user name="UserTwo" user_id="10">
   <projects>      
      <project Y="1" name="ProjectThree" user_id="10" />
   </projects>
</user>

I'm pretty new to all of this, so I won't be surprised if I'm doing something completely wrong. Any help would be appreciated.

use //users[@user_id='?']/projects in place of urs.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.