Reputation: 51
I'm still relatively new to Xpath.
I'm wondering how exactly I would use a variable to generate a url.
For instance, one application I'm using has a different XML document URL for each date.
So one URL might be http://www.example/2014-09-01.xml.
I need to retrieve a large number of these URLs based on the current date. I'm not sure how one would insert a $variable into a statement like doc("URL")/filters
Upvotes: 0
Views: 691
Reputation: 295383
The syntax for variables in XPath is simply $varname
. So:
doc($url)/filters
The method for passing in variables in from an out-of-band tool or processing engine varies with that processing engine. With XMLStarlet, for instance, that might be:
xmlstarlet sel --var url "http://www.example.com/$date.xml"
...or, with the BaseX command-line interface:
basex -b'$url='"http://www.example.com/$date.xml"
Upvotes: 2
Reputation: 11771
let $URI := concat('http://www.example/', $date, '.xml')
return doc($URI)
Upvotes: 2