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

RE: Good old namespace problem(slightly different)!!

Subject: RE: Good old namespace problem(slightly different)!!
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Wed, 30 Apr 2003 13:57:22 -0400
xsl template pass in namespace
[XSL Chatr]
>...
> 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...

No, you do not have to do that, and it is bad practice if there are any
other althernative (search in the FAQs or the list archives for more on
this).

What you want to to is to add the namespace as you copy each of the
imported elements.  You can do this by modifying the standard identity
template so that you get a chance to modify each element as it gets
processed -

<xsl:template match="/">
  <myheader 
		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xsi:schemaLocation="www.abc.org/schema/mainschema.xsd" 
		supplier="My Company Ltd">
   <xx>
    <xsl:apply-templates select="$imported-xml" mode='import'/>
   </xx>
  </myheader >
 </xsl:template>
 
<!-- Here you add the namespace to each element and otherwise copy its
contents --> 
<xsl:template match='*' mode='import'>
   	<xsl:element name='{name()}' namespace='www.abc.org'> 
   		<xsl:apply-templates select='@*' mode='import'/>
 		<xsl:apply-templates select="* | text()" mode='import'/>

 	</xsl:element> 
 </xsl:template> 
     
<!-- Here you pick up any attributes -->
<xsl:template match='@*' mode='import'>
	<xsl:copy-of select='.'/>
</xsl:template>

I used the mode "import" to avoid any conflict with other templates you
might want to write that will not be handling the imported xml.  With
this approach you do not have to put a default namespace declaration
into "myheader" - the stylesheet will insert it for you in the top-level
element of the imported document.

Cheers,

Tom P

 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.