|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Good old namespace problem(slightly different)!!
[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
|
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
|






