[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Changing namespaces

Subject: Changing namespaces
From: Pradnya Gawade <pradnya.gawade7@xxxxxxxxx>
Date: Mon, 15 Aug 2011 17:09:34 -0400
 Changing namespaces
Hi folks,

I am trying to achieve some XSLT transformation and having hard time
in getting the exact output. Any help will nbe highly appreciated.

My input xml has elements from 2 namespaces. One is my default
namespace and another with namespace prefix as 'OC:'. Target is to
strip out all the elements and attributes with this prefix 'OC:'
except the selected once. I try to achieve this by using identity
template modified for my requirements in following steps:
1. Use copy template and specify not to copy any elements/attribute
from the namespace corresponding to prefix 'OC:'
2. In a separate templates copy selectively the elements and
attributes I want to retain in the output.

After struggling a lot for the issue of namespances uri getting
displayed in the individual elements I copy selectively in last step,
I finally got it correct. Now the only difficulty I am having is
getting the root element with right namespace URIs in it. I wish to
have default namespace changed to some thing else, say
"new-default-namespace" and namepsace corresponding to prefix 'OC:'
changed to some thing else, say "new-oc-namespace-uri". I went through
lot on similar postings online but could not get the perfect solution.

My xsl stylesheet is as follows:

<xsl:stylesheet version="2.0"
	xmlns:odm="old-default-namespace"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance"
xmlns:def="http://www.cdisc.org/ns/def/v1.0"
	xmlns:xlink="http://www.w3c.org/1999/xlink" xmlns:OC="old-oc-namespace-uri"
	xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
	exclude-result-prefixes="xlink" xmlns:exsl="http://exslt.org/common">

	<!-- standard copy template -->
	<xsl:template name="copyTemplate" match="node()|@*">
		<xsl:copy>
			<xsl:apply-templates select="@*|node()" />
		</xsl:copy>
	</xsl:template>


<xsl:template name="removeOCExtnElmnt" priority="3" match="//*[
namespace-uri()='old-oc-namespace-uri' ]" ></xsl:template>

<xsl:template name="removeOCExtnAttrib" priority="2" match="//@*[
namespace-uri()='old-oc-namespace-uri' ]" ></xsl:template>

<xsl:template priority="4" match="@ODMVersion">
	<xsl:attribute name="ODMVersion">1.2</xsl:attribute>
</xsl:template>
		
<xsl:template priority="5" match="OC:MultiSelectList |
OC:MultiSelectListRef | OC:MultiSelectListItem">
	<xsl:element name="{name()}" namespace="{namespace-uri()}" >		
		<xsl:copy-of select="@*"/>
			<xsl:apply-templates/>
		</xsl:element>
</xsl:template>
	
<xsl:template priority="6" match="//*[@OC:StudySubjectID |
@OC:UniqueIdentifier | @OC:Status
	| @OC:DateOfBirth | @OC:Sex | @OC:StudyEventLocation | @OC:StartDate
	| @OC:SubjectAgeAtEvent | @OC:Version | @OC:InterviewerName
	| @OC:InterviewDate | @OC:Status]">
	<xsl:element name="{name()}" namespace="{namespace-uri()}">
		<xsl:copy-of select="@*" copy-namespaces="no"/>
			<xsl:apply-templates/>
		</xsl:element>
</xsl:template>

</xsl:stylesheet>

Root element in my present output and input xml is:
<ODM xmlns="old-default-namespace" xmlns:OC="old-oc-namespace-uri"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
FileOID="oc_extn_testD20110809115446-0400" Description="oc_extn_test"
CreationDateTime="2011-08-09T11:54:46-04:00" FileType="Snapshot"
ODMVersion="1.2"
xsi:schemaLocation="http://www.cdisc.org/ns/odm/v1.3OC-ODM1-3-0-OC2-0.xsd">

I expect it to be changed to:

<ODM xmlns="new-default-namespace" xmlns:OC="new-oc-namespace-uri"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
FileOID="oc_extn_testD20110809115446-0400" Description="oc_extn_test"
CreationDateTime="2011-08-09T11:54:46-04:00" FileType="Snapshot"
ODMVersion="1.2"
xsi:schemaLocation="http://www.cdisc.org/ns/odm/v1.3OC-ODM1-3-0-OC2-0.xsd">


Thanks in advance.

- Pradnya

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.