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:<xsl:variable select="SuperTag" name="zgtag"/>
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:
<xsl:choose>
<xsl:when test="//z:tag=''">
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:
<xsl:template match="/">
<xsl:variable select="'SuperTag'" name="zgtag"/>
<xsl:for-each select="/z:profile-extension">
<xsl:choose>
<xsl:when test="//z:tag=$zgtag">
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.
--var zgtag="'SuperTag'"
and also remove the single quotes in the expression around$zgtag
? – Kusalananda Feb 07 '24 at 10:00$
. I didn't spot that due to the amount of text. – Kusalananda Feb 07 '24 at 10:07--var zgtag="'fbfBfzgartAudiquattro'" -t -m "/z:profile-extension" -i "//z:tag=$zgtag"
, i get the errorcould not compile test expression '//z:tag='
– basZero Feb 07 '24 at 14:50$
so that the shell does not think that$zgtag
is a shell variable. – Kusalananda Feb 07 '24 at 15:54<xsl:when test="//z:tag=$zgtag">
, but as I said, it still does not work. – basZero Feb 08 '24 at 07:34