Passing a Flow Variable in XPath Query

Hi,

I am working on an XML file using the XPath node where I have a test structure as follows.  I need to find the immediate parent node of any given employee using //Employee[@id=<nodeid>]/parent::*/@id which works as I verified on online XPath testers.

To iterate over the entire range of Employee IDs, I used the Ungroup node and the Table Row to Variable Loop start node, and the iteration works all well, with one problem: I need to pass the variable currentNodeId on to the XPath above so I can get a return of the immediate parent.  I tried using the variable port and saw that the currentNodeId is now part of the flow variables in the XPath (under Flow Variables), and typed: //Employee[@id=currentNodeId]/parent::*/@id but this does not seem to work.  I tried something like $currentNodeId$ but I got a syntax error.

How can I get this problem resolved?

Thanks!

<?xml version="1.0" encoding="UTF-8"?>
<Employees>
    <Employee id="1">
       <name>John</name>

       <Employee id="2">
                  <name>Lisa</name>
       </Employee>
   </Employee>
 <Employee id="3">
<name>Tom</name>
 </Employee>
 <Employee id="4">
       <name>Dave</name>
 </Employee>

</Employees>

I think you need to create the XPath in advance for example with the Java Snippet Variable node (something like: return "//Employee[@id=" + c_currentNodeId + "]/parent::*/@id";) and pass that xpath formula to the XPath node.

Cheers, gabor

Gabor, thank you for your solution.  It worked with a slight modification: I created a variable using the Java Snippet Variable node xpath_string = "//Employee[@id=" + c_currentNodeId + "]/parent::*/@id"; (it complained about the return since it was void data type).  I passed that variable to the XPath node using the variable flows.  It works perfectly now.