Expand my Community achievements bar.

How to select a specific XML node with XPath

Avatar

Former Community Member
Hi,

I'm trying to a select a specific node from my XML data using the XPath Builder. For example, say I have a process variable 'xmlData' with the
following contents:



User 1
101


User 2
102



I can successfully use the following expression to retrieve the name of
a specific user:

(/process_data/xmlData/users/user[userid='102'])/name

The problem is I need to use another process variable for the selection
key. For Example:

(/process_data/xmlData/users/user[userid=/process_data/@userId])/name

But this always returns null. I've tried surrounding /process_data/@userId
with single quotes, double quotes, and event {$..$}.

Any help would be greatly appreciated.

Thanks.
8 Replies

Avatar

Former Community Member
Hi,



Try number(/process_data/@userid) but I'm not sure

Avatar

Level 10
Jerome is right try the following:



/process_data/xmlData/users/user[userid='number(/process_data/@userId)']/name



Jasmin

Avatar

Former Community Member
Hi,

Thanks for the quick replies. I gave a bit of a bad example, as the
userid in my data is really a string, not a number.

A better example is:



User 1
user1


User 2
user2



I can get the following to work perfectly:

(/process_data/xmlData/users/user[userid='user2'])/name

but I can't get it to work with

/process_data/@userId = "user2"

(/process_data/xmlData/users/user[userid=/process_data/@userId])/name

Thanks.

Avatar

Level 10
Don't forget the quotes around /process_data/@userid



/process_data/xmlData/users/user[userid='/process_data/@userId'])/name



Jasmin

Avatar

Former Community Member
Hi,



I've tried surrounding with single quotes, then double quotes, even

the template operators {$/process_data/@userId$}, and then the template

operators surrounded by single and double quotes. None of these

seem to work.

Avatar

Former Community Member
Hi,

Is there any solution? I encounter the same problem. Seem like a simple job but difficult to archeive...

Avatar

Former Community Member
have you found a solution to your problem,if not email me

mergeandfuse@gmail.com,will help you out

thaanks

girish

Avatar

Level 9
Just a thought: try:

/process_data/xmlData/users/user[userid=string(/process_data/@userId)])/name

Please post a reply if this works/doesn't.

Howard

http://www.avoka.com