[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Changing namespaces
On 15/08/2011 22:09, Pradnya Gawade wrote:
My xsl stylesheet is as follows: <xsl:element name="{name()}" namespace="{namespace-uri()}"> this (and similar lines) generates elements with the same local name and namespace as the source, but you want to change the namespace. your sample input is a bit short and doesn't show any elements or attributes in the namespace with prefix OC: so i'm having to guess a bit but something like: chg.xml <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"> <foo OC:zz="1" a="b"/> <OC:bar x="y" OC:x="z"/> </ODM> chg.xsl
<xsl:template match="olddef:*"> <xsl:element name="{local-name()}" namespace="new-default-namespace-uri"> <xsl:namespace name="OC" select="'new-oc-namespace-uri'"/> <xsl:apply-templates select="@*,node()"/> </xsl:element> </xsl:template> <xsl:template match="oldOC:*"> <xsl:element name="OC:{local-name()}" namespace="new-oc-namespace-uri"> <xsl:apply-templates select="@*,node()"/> </xsl:element> </xsl:template> <xsl:template match="@oldOC:*"> <xsl:attribute name="OC:{local-name()}" namespace="new-oc-namespace-uri"> <xsl:value-of select="."/> </xsl:attribute> </xsl:template> </xsl:stylesheet> $ saxon9 chg.xml chg.xsl <?xml version="1.0" encoding="UTF-8"?><ODM xmlns="new-default-namespace-uri" 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"> <foo OC:zz="1" a="b"/> <OC:bar x="y" OC:x="z"/> </ODM>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|