1
votes

With the following file.xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<config>
 <index type="I8">
  <book>2</book>
 </index>
</config>

I can't select book with

xmlstarlet sel --template --match /config/index[@type="I8"] -c . file.xml

I can't select book with

xmlstarlet sel --template --match /config/index[@type='I8'] -c . file.xml

I can select book with

xmlstarlet sel --template --match "/config/index[@type='I8']" -c . file.xml

I can select book with

xmlstarlet sel --template --match '/config/index[@type="I8"]' -c . file.xml

Also if type is type="8" in xml, I can select it with:

xmlstarlet sel --template --match /config/index[@type="8"] -c . file.xml

Why?

xmlstarlet 1.6.1
compiled against libxml2 2.9.4, linked with 20904
compiled against libxslt 1.1.29, linked with 10129
1
I can reproduce this error with xmlstarlet 1.6.1. Double-Check with xsltproc results in expected behaviour, so this is probably an xmlstarlet error.zx485
What's the result with /config/index[@type=string("I8")] or /config/index[string(@type)="I8"]or /config/index[normalize-space(@type)="I8"] ?E.Wiest
@E.Wiest, I'm in bash shell, parantheses are interpreted as sub-shell.David Bonnin
Even with single quotes enclosures ? Like : 'xmlstarlet sel --template --match /config/index[@type=string("I8")] -c . file.xml'E.Wiest
In bash? don't work.David Bonnin

1 Answers

1
votes

This one works (tested on Windows and on Ubuntu):

xmlstarlet sel -t -i /config/index/@type=\"I8\" -m //book -c . -b file.xml

It has something to do with quoting, you can see why when looking at the output of next statement:

xmlstarlet sel -C --template --match /config/index[@type="I8"] -c . file.xml

it's output:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output omit-xml-declaration="yes" indent="no"/>
  <xsl:template match="/">
    <xsl:for-each select="/config/index[@type=I8]">
      <xsl:copy-of select="."/>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

which is missing quotes around the I8.