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
Harry Potter
29.99
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:
...
...
This results in namespace nodes, child nodes, and attributes nodes being included, cf. the XSLT spec (see w3schools summary).