Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Changing namespace uri using xslt

 
Shane Lee
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20958
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.... ;-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic