Use result of XPath expression in another XPath expression

I am using XML Reader and XPath to retrieve string values.
My (first) XPath expression =
//odm:ItemGroupDef[@Name=‘AE’]/odm:ItemRef[@KeySequence]/@ItemOID
leading to a multiple row table with the column name “AE”.
I now want to use these values in a second XPath expression using the same input XML, also getting a similar multiple row.
Something like:
//odm:ItemDef[@OID=$AE$]/@Name
Can this be done in the same XPath node, or do I need extra nodes?
For clarity, please find a snapshot of the first XPath expression below.

grafik

Hi,

You can use a “String Manipulation” node and create the XPath and convert it to a flow variable and then feed a new XPath node with it.
Expression for the String Manipulation node:
join("//odm:ItemDef[@OID='", $AE$, "']/@Name")

You have to do this in a loop so in each loop iteration you create a new path and extract the corresponding value.

Best,
Armin

Thanks!
Any example file available? I am an absolute beginner, so I even do not know how to do things in a loop …

Is it possible for you to share the XML file or a sample file so that I can implement the solution as an example?

Of course! Please find it attached.
It comes from the CDISC Define-XML standard v.2.0 distribution
define2-0-0-example-sdtm.xml (358.9 KB)

Here you are:


xpath.knwf (98.7 KB)

But as it seems that the name is actually the last part of the OIDs, I did the same task with a single String Manipulation node as well.

Best,
Armin

Great many thanks! I will try it out.
The name being the last part of the OID is just “by accident” - we cannot trust on the naming convention used here in this example. The OID could as well have been “a905c864-6aa1-11e9-a923-1681be663d3e”, i.e. a uuid.

It works great! As a KNIME beginner, I am learning a lot thanks to people like you. Highly appreciated!
Jozef

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.