Subject: RE: [xsl] Good old namespace problem(slightly different)!! From: "Michael Kay" <mhk@xxxxxxxxx> Date: Wed, 30 Apr 2003 21:07:02 +0100 |
If you want the new elements to be in namespace "www.abc.org" when the old elements were in no namespace, then you are modifying them rather than copying them. To do this you can't use xsl:copy-of, you have to walk the tree using xsl:apply-templates and a template rule that does something like: <xsl:template match="*" mode="change-namespace"> <xsl:element name="local-name()" namespace="www.abc.org"> <xsl:apply-templates/> </xsl:element> </xsl:template> Michael Kay > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of XSL Chatr > Sent: 30 April 2003 17:07 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] Good old namespace problem(slightly different)!! > > > Hi all, > Could some one please help me.I checked up the list and some > websites but coudnt find a satisfactory solution.Here goes > the problem.... Pasting you the cut down simulated version... > > I have a source xml like ... > > > <?xml version="1.0"?> > <strings> > <str>Parent</str> > > </strings> > > > and another xml file(imported.xml)with structure as > > <?xml version="1.0"?> > <imported-xml> > <child1>child1</child1> > <child2>child2</child2> > <child3>child3</child3> > <child4>child4</child4> > <child5>child5</child5> > </imported-xml> > > > > > and my XSl prints the imported xml structure > <?xml version="1.0"?> > <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > <xsl:output method="xml"/> > <xsl:variable name="imported-xml" select="document('imported.xml')"/> > <xsl:template match="/"> > <myheader xmlns="www.abc.org" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="www.abc.org/schema/mainschema.xsd" > supplier="My Company Ltd"> > <xx> > <xsl:copy-of select="$imported-xml"/> > </xx> > </myheader > > </xsl:template> > </xsl:stylesheet> > > > And my result is ... > > > <?xml version="1.0" encoding="UTF-16"?> > <myheader xsi:schemaLocation="www.abc.org/schema/mainschema.xsd" > supplier="My Company Ltd" xmlns="www.abc.org" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> > <xx> > <imported-xml xmlns=""> <!-- attribute xmlns appears.. but > is unwanted --> > <child1>child1</child1> > <child2>child2</child2> > <child3>child3</child3> > <child4>child4</child4> > <child5>child5</child5> > </imported-xml> > </xx> > </myheader> > > notice that there is an attribute xmlns = "" added to the > element <imported-xml> i dont want this to happen .. what i want is: > > > <?xml version="1.0" encoding="UTF-16"?> > <myheader xsi:schemaLocation="www.abc.org/schema/mainschema.xsd" > supplier="My Company Ltd" xmlns="www.abc.org" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> > <xx> > <imported-xml> <!-- without that annoying xmlns attribute--> > <child1>child1</child1> > <child2>child2</child2> > <child3>child3</child3> > <child4>child4</child4> > <child5>child5</child5> > </imported-xml> > </xx> > </myheader> > > > Now i understand that this is because of the<myheader > xsi:schemaLocation="www.abc.org/schema/mainschema.xsd" > supplier="My Company Ltd" xmlns="www.abc.org" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> > element with namespace declarations > > So, to get rid of this, i enclosed them in CDATA section like... > > <?xml version="1.0"?> > <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > <xsl:output method="xml"/> > <xsl:variable name="imported-xml" select="document('imported.xml')"/> > <xsl:template match="/"> > <xsl:text disable-output-escaping="yes"> > <![CDATA[ > <myheader xsi:schemaLocation="www.abc.org/schema/mainschema.xsd" > supplier="My Company Ltd" xmlns="www.abc.org" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> > ]]> > </xsl:text> > <xx> > <xsl:copy-of select="$imported-xml"/> > </xx> > <xsl:text disable-output-escaping="yes"> > <![CDATA[</glf>]]> > </xsl:text> > </xsl:template> > </xsl:stylesheet> > > This works fine with the result i want.. as in.. > > <?xml version="1.0" encoding="UTF-16"?> > <myheader xsi:schemaLocation="www.abc.org/schema/mainschema.xsd" > supplier="My Company Ltd" xmlns="www.abc.org" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> > <xx> > <imported-xml> <!-- without that annoying xmlns attribute--> > <child1>child1</child1> > <child2>child2</child2> > <child3>child3</child3> > <child4>child4</child4> > <child5>child5</child5> > </imported-xml> > </xx> > </myheader> > > > Dont know if this is an ugly way of doing this. could anyone > suggest me if i can do this without that cdata section? > > Thanks > > Xsl chatr > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Good old namespace proble, David Carlisle | Thread | RE: [xsl] Transform XML, Bryan Archer |
Re: [xsl] japanese sorting, Eric Promislow | Date | RE: Re: [xsl] Transform XML, cknell |
Month |