[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Add namespace to element name itself


Subject: RE: [xsl] Add namespace to element name itself
From: "V.Ramkumar" <v.ramkumar@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 18 Nov 2008 18:07:15 +0530

>You'll have to tell us more precisely (a) what you are doing, and (b) what
>output you actually do want.

Dear Michael,
 
I am doing XML (input) to XML (output) Transformation using saxon9.

I have to add namespace to output XML name itself in transformation.

I need like this <ce:pii>.

I am giving here, some parts of the sample file. I have to add some
namespace to output xml by using xslt transform.

I have to add namespace for some root elements not for all elements.

How to add namespace to all the elements of the parent. By matching single
parent element, like the below,
 
 My input XML contains,
 	<item-info>
 		<jid>YFMIC</jid>
 		<aid>1120</aid>
 		<pii>S0740-0020(08)00080-4</pii>
 		<doi>10.1016/j.fm.2008.04.010</doi>
 		<copyright type="unknown" year="2008"/>
 	</item-info>
 
 Required output XML,
 	<item-info>
 		<ce:jid>YFMIC</jid>
 		<ce:aid>1120</aid>
 		<ce:pii>S0740-0020(08)00080-4</ce:pii>
 		<ce:doi>10.1016/j.fm.2008.04.010</ce:doi>
 		<ce:copyright type="unknown" year="2008"/>
 	</item-info>
 
 My XSL:
 	<xsl:template match="*">
 		<xsl:copy>
 			<xsl:copy-of select="@*"/>
 			<xsl:apply-templates/>
 		</xsl:copy>
 	</xsl:template>
 
	<xsl:template match="pii"><xsl:element
name="ce:{local-name()}"><xsl:apply-templates select="@*|node()"
/></xsl:element></xsl:template>
	<xsl:template match="doi"><xsl:element name="ce:{local-name()}"
namespace="uri"><xsl:apply-templates select="@*|node()"
/></xsl:element></xsl:template>
	<xsl:template match="copyright"><xsl:element
name="ce:{local-name()}" namespace="uri"><xsl:apply-templates
select="@*|node()" /></xsl:element></xsl:template>
 
Regards,
Ramkumar


Current Thread
Keywords