I am looking for a way to extract and print an element from my xml using xmlstarlet; for example if my xml is
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).