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

Good old namespace problem(slightly different)!!

Subject: Good old namespace problem(slightly different)!!
From: "XSL Chatr" <xsl_chatr@xxxxxxxxxxx>
Date: Wed, 30 Apr 2003 17:07:27 +0100
problem child2
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


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.