Hi,
I'm trying to add an attribute to the root element in some XML. The XML can come from several sources and the root element name will be unknown.
I'm no expert on XSLT but I've managed to get this far...
WITH t as (SELECT XMLTYPE('<MyRoot><Child1>Fred</Child1><Child2>Mike</Child2></MyRoot>') as v_xml from dual)
SELECT XMLTRANSFORM(t.v_xml, XMLTYPE('<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/*"><xsl:copy><xsl:attribute name="xmlns">fred</xsl:attribute><xsl:apply-templates /></xsl:copy></xsl:template></xsl:stylesheet>')) xml FROM t
Which doesn't quite give me what I want. What I want would be (in this example)...
<MyRoot xmlns="fred">
<Child1>Fred</Child1>
<Child2>Mike</Child2>
</MyRoot>
Any help much appreciated, thanks.