This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*">
<xsl:element name="{name()}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
<xsl:template match="text()">
<value>
<xsl:value-of select="."/>
</value>
</xsl:template>
</xsl:stylesheet>
when applied on the provided XML document:
<book author="Name" year="2000">Book title</book>
produces the wanted, correct result:
<book><author>Name</author><year>2000</year><value>Book title</value></book>
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 value
parent element.
Do note: The use and overriding of the identity rule is the most fundamental and powerful XSLT design pattern.
I would like to do it with xslt or
something I can run from bash...
Most XSLT processors come with a command-line utility that invokes an XSLT transformation from the command line. Read your XSLT processor's documentation.