Subject: RE: [xsl] Good old namespace problem(slightly different)!! From: "Passin, Tom" <tpassin@xxxxxxxxxxxx> Date: Wed, 30 Apr 2003 13:57:22 -0400 |
[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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] How to determine that no , Passin, Tom | Thread | RE: [xsl] Good old namespace proble, Passin, Tom |
[xsl] How to determine that no resu, Karl J. Stubsjoen | Date | RE: [xsl] document() access. The co, Américo Albuquerque |
Month |