here is what I would like to do:
Convert this XML:
<book author="Name" year="2000">Book title</book>
To this XML:
<book><author>Name</author><year>2000</year><value>Book title</value></book>
I would like to do it with xslt or something I can run from bash…
Thanks.
This transformation:
when applied on the provided XML document:
produces the wanted, correct result:
Explanation:
The identity rule/template copies every node “as-is”.
We override the identity rule with a template matching any attribute. It creates an element whose name is the name of the matched attribute and whose only text-node child is the value of the matched attribute.
Finally, we override the identity rule with a template that matches any text node. It simply outputs this node wrapped in a
valueparent element.Do note: The use and overriding of the identity rule is the most fundamental and powerful XSLT design pattern.
Most XSLT processors come with a command-line utility that invokes an XSLT transformation from the command line. Read your XSLT processor’s documentation.