How to select a specific XML node with XPath

Avatar

02-07-2008

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.

Replies

Avatar

Avatar

_jerome_dinnat_

Avatar

_jerome_dinnat_

_jerome_dinnat_

02-07-2008

Hi,



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

Avatar

Avatar

Jasmin_Charbonn

Avatar

Jasmin_Charbonn

Jasmin_Charbonn

02-07-2008

Jerome is right try the following:



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



Jasmin

Avatar

02-07-2008

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

Avatar

Jasmin_Charbonn

Avatar

Jasmin_Charbonn

Jasmin_Charbonn

02-07-2008

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



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



Jasmin

Avatar

02-07-2008

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

12-08-2008

Hi,

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

Avatar

13-08-2008

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

mergeandfuse@gmail.com,will help you out

thaanks

girish

Avatar

Avatar

HowardTreisman

Avatar

HowardTreisman

HowardTreisman

27-08-2008

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