Reputation: 33
I have a bash-script, that traverses through multiple directories and parses data from a few XML files. I am using XQilla to execute my XQueries.
echo "---|Reading names|---"
../../xqilla .._name.fcs >> /var/lib/mysql-files/name.txt
And this is the XQuery:
for $fw in doc("./network_objects.xml")/network_objects/network_object
where $fw/interfaces/interfaces/ipaddr
return (data($fw/Name))
How can I pass a variable from the bash-script to XQuery, so that I can search for different items, depending on the cwd, for example?
Upvotes: 3
Views: 680
Reputation: 79
#!/bin/dash
echo "Alpha
Bravo
Charlie
Delta" |
while read name; do
echo "/network_objects/network_object[Name='$name'][interfaces/interface/ipaddr]/Name/string()" |
xqilla -i ./network_objects.xml /dev/stdin
done
Upvotes: 0
Reputation: 38672
Use xqilla's -v
option to pass an external variable (which is a standardized XQuery concept):
-v <name> <value> : Bind the name value pair as an external variable
In XQuery, make sure to declare that variable as external.
For example, call an XQuery script passing the $foo
variable with value bar
:
xqilla -v foo bar test.xq
And use this variable by declaring it in the script's header:
declare variable $foo external;
concat("Value of $foo is: ", $foo)
Upvotes: 2