How can I use an XPATH with a parameterized value in a rest call
I have a GET that stores values in a Datasource using an XML Databank
I then want to extract a value from my next GET based on value in the Datasource.
For example, say in the first GET, I store 2 for the number of widgets in the Datasource.
Then the next GET has another XML Databank that extracts one part for each widget - in this case, 2 widgets. If I always knew the that number of wdgets was 2, then I could have 2 requests with the following XPATHs:
/:partList/part[][partType=7][1]/location[1]/text()
/:partList/part[][partType=7][2]/location[1]/text()
But since I don't know the number of widgets, I need a way to parameterize the number in the XPATH based on the number of widgets in the Datasource, e.g.,
/:partList/part[][partType=7][{$numberOfWidgets}]/location[1]/text()
Best Answer
-
It looks like you have a syntax error in your parameterization:
/:partList/part[][partType=7][{$numberOfWidgets}]/location[1]/text()There should be a curly bracket after the dollar sign: ${variable}
Please note that when using the ${ } syntax in your DataBank xpath, the xpath may not evaluate successfully in the result window, but it will parameterize as expected during run time.
5
Answers
-
Mr. Quantum,
Have you tried wrapping your xpath in "count(xpath)" to determine the count of a particular element?
For example,
count( /:partList/part[][partType=7]/location/text() )You may then store this value in DataSource column and parameterize it using ${numberOfWidgets}
0 -
Omar, Thank you. Perhaps I am thinking about this wrong but my challenge is then getting that count result into an XPATH. How does one do that?
0 -
Thank you, this now makes sense and works.
0