Passing a Flow Variable in XPath Query


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?


<?xml version="1.0" encoding="UTF-8"?>
    <Employee id="1">

       <Employee id="2">
 <Employee id="3">
 <Employee id="4">


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.