aspose file tools*
The moose likes XML and Related Technologies and the fly likes Changing namespace uri using xslt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Changing namespace uri using xslt" Watch "Changing namespace uri using xslt" New topic
Author

Changing namespace uri using xslt

Shane Lee
Ranch Hand

Joined: Mar 19, 2005
Posts: 63
Did not think this would be a huge issue but it is!
Ok the xml i am working on i need to change the root element MsgCiceroTxn to MsgCourtLinkTxn and the namespace uri http://www.agd.nsw.gov.au/xml_cicero/fms to http://www.agd.nsw.gov.au/xml_courtlink/fms.

MY sample xml message that i am working of is:


And my xsl is:


This does not change anything not even the element name!

If i change my xsl to point to element fms:Receipt instead and change the root namespace to the old one xmlns:fms="http://www.agd.nsw.gov.au/xml_cicero/fms (Just for test purposes):
<xsl:template match="fms:Receipt">
<xsl:element name="fms:Receipt" namespace="http://www.agd.nsw.gov.au/xml_courtlink/fms">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>

the following transformation output occurred then:


Any solution, can i just say i hate namespaces!!!
Thanks,
Shane.


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18114
    
    8



Didn't we do this before? Maybe it was someone else, the question comes up often enough.

That element matches a MsgCiceroTxn element which isn't in any namespace. Your MsgCiceroTxn elements are all in the default namespace, which is a namespace, so you don't match it.

Declare your default namespace URI (from the XML document) as a namespace with a prefix in your XSLT. Then match on the element with that prefix.
Shane Lee
Ranch Hand

Joined: Mar 19, 2005
Posts: 63
haha thanks paul ive been spending all day on this today. How to access the root element not knowing that yes it is in a default namespace but with no prefix, but i still needed to refer to the element name by a prefix in my xsl.

As for the other part removing the default namespace and changing it to a different namespace uri, that was really tricky. For anyone that wants xsl to change default namespace uri and its sibling(again i think this is bad xml code standard to call the same namespace uri even though it is the root default, i didnt code the xml output!) and change the root element of the xml document here you go:



Thanks again paul, namespaces are killing me.... ;-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Changing namespace uri using xslt
 
Similar Threads
jdom and jaxen question
Another XML Conversion Problem
Namespace problem in xslt
Replacing an element value in xml using xsl
XSL Problem