Extracting and dumping elements using xmlstarlet Extracting and dumping elements using xmlstarlet xml xml

Extracting and dumping elements using xmlstarlet


Using the "-c" (copy) option, should achieve what you're after:

xmlstarlet sel -t -c "/bookstore/book[price=29.99]" books.xml<book>  <title lang="eng">Harry Potter</title>  <price>29.99</price></book>

You can watch the XSLT generated internally in xmlstarlet by adding the global "-C" switch after "sel". This shows how the copy option results in an xslt copy-of construct:

...<xsl:template name="t1">  <xsl:copy-of select="/bookstore/book[price=29.99]"/></xsl:template>...

This results in namespace nodes, child nodes, and attributes nodes being included, cf. the XSLT spec (see w3schools summary).