I have this command:
find . -iname '*.xml' | xargs xmlstarlet sel -N z="http://abc.com/article/1.0/ " \\
--var zgtag="SuperTag" -t -m "/z:profile-extension" -i "//z:tag='$zgtag'" \\
-n -f -o "," -v "count(//z:zgContextsAnonymTotal[z:tag='$zgtag'])" -o "," \\
-v "//z:zgContextsAnonymTotal/z:tag[.='$zgtag']/@z:timestamp" -o "," \\
-v "count(//z:zgContextsREGTotal[z:tag='$zgtag'])" -o "," \\
-v "//z:zgContextsREGTotal/z:tag[.='$zgtag']/@z:timestamp" -o "," \\
-v "count(//z:zgContextsPremiumTotal[z:tag='$zgtag'])" -o "," \\
-v "//z:zgContextsPremiumTotal/z:tag[.='$zgtag']/@z:timestamp" | grep -v ^$
It does not work because the command version without variable (same value repeated instead of using $zgtag
show results. What is wrong?
**My investigation so far pointed out:**
- It has to be --var zgtag="'SuperTag'"
because without single quotes the compiled XSLT by xmlstarlet would produce the following variable declaration: `` which is obviously wrong, the single quotes are missing!
- In the XSLT compiled by xmlstarlet I can see that the variable is NOT inserted correctely, e.g. I see this:
Then I used this version: --var zgtag="'SuperTag'" -m "/z:profile-extension" -i '//z:tag=$zgtag'
, now I get a correctly compiled XSLT debugging output of xmlstarlet:
However the output still is empty, the same script without the variable (SuperTag
directly inserted into the script multiple times) works just fine. So there must be still a problem with this var-styled command.
So any help welcome how to insert and use the defined variable correctly. The definition is not the problem, it's the usage of the variable in the xmlstarlet command.
Asked by basZero
(153 rep)
Feb 7, 2024, 09:56 AM
Last activity: Feb 8, 2024, 08:21 AM
Last activity: Feb 8, 2024, 08:21 AM