How can I use an XPATH with a parameterized value in a rest call

BrianQuantumBrianQuantum Posts: 20

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

Answers

  • OmarROmarR Posts: 186 admin
    edited June 2017

    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}

  • BrianQuantumBrianQuantum Posts: 20

    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?

  • BrianQuantumBrianQuantum Posts: 20

    Thank you, this now makes sense and works.

Sign In or Register to comment.