I am trying to use XSL to transform an XML file and can’t figure out how to rename an element as either the name or value of one of its attributes. I have found plenty of examples of converting attributes to elements and the other way around but I keep ending up with elements that are nested which I don’t want. Here is an example:
Original XML:
<row_item column="Hostname">HOST-A</row_item>
<row_item column="IP Address">10.10.10.10</row_item>
What I would like to output:
<column>HOST-A</column>
Or (preferred):
<hostname>HOST-A</hostname>
This transformation:
when applied on this XML document:
produces the wanted, correct result:
Explanation:
Appropriate use of
xsl:elementand AVT.