xsl-list
[Top] [All Lists]

Good old namespace problem(slightly different)!!

2003-04-30 09:07:27
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



<Prev in Thread] Current Thread [Next in Thread>