Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Add Attribute to root element

BluShadowJul 25 2006 — edited Jul 25 2006
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 22 2006
Added on Jul 25 2006
7 comments
928 views