Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

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!

change the namespace and copy all the rest of an xml using xslt

800344Apr 14 2009 — edited Apr 16 2009
Dear all,

I have an xml file with a namespace "http://com.mytest/old_name_space". I want to use xslt to copy this xml file without changing any thing except I want to replace the name space with the new one "http://com.mytest/old_name_space".

I modified some codes I took from an article but I failed.

Could you provide a help?

Regards.

Pengyou

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:from="http://com.mytest/old_name_space"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   version="1.0">
	<xsl:output method="xml" encoding="iso-8859-1" indent="yes"/>

	<xsl:template match="from:*">
		<xsl:element name="{name(.)}" namespace="http://com.mytest/new_name_space">
							<xsl:apply-templates select="@*|node()"/>
		</xsl:element>
	</xsl:template>

	<!-- copy values -->
	<xsl:template match="@*">
		<xsl:choose>
			<xsl:when test="local-name(.) ='schemaLocation'">
			</xsl:when>
			<xsl:otherwise> 
				<xsl:copy/>
			</xsl:otherwise>
		</xsl:choose>  
	</xsl:template>
</xsl:stylesheet>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 14 2009
Added on Apr 14 2009
6 comments
312 views