Reputation: 1252
I have a reporting requirement where a query will be exactly the same except for a few XPath expressions depending on what column needs to be filtered on in a where clause.
where $record/firstName eq $firstName
vs
where $record/lastName eq $lastName
How can I use a dynamic XPath so I can use the same code for both and pass in the path as a parameter?
Upvotes: 0
Views: 230
Reputation: 7335
Queries and XPaths are fundamentally different:
A subset of XPaths (known as searchable expressions) can be treated as queries behind the scenes, but there's no particular advantage to the XPaths in those cases -- the same thing can be expressed as a query.
With that as context, one possibility is to construct the queries dynamically, nesting element or JSON scope (aka container) queries to express the path. Would that meet your requirements? If not, can you expand on the use case?
One thing to be aware of: for precise scope queries, you either have to turn on positions or execute a filtered query.
Hoping that helps,
Upvotes: 1