Subject: Re: [xsl] Adding namespace nodes question From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Mon, 17 Dec 2001 15:32:34 +0000 |
Mike Kay wrote: > AFAIK the only way to add a namespace node to the result tree, when > the namespace isn't present in either the source document or the > stylesheet, is to create an element on a temporary tree that uses > that namespace, and then use xsl:copy[-of] to copy the namespace > node from the temporary tree to the result tree. Even this relies on > (a) the errata to XSLT 1.0, and (b) the xx:node-set() extension. > > <xsl:variable name="temp"> > <xsl:element name="{$prefix}.temp" namespace="{.}"/> > </xsl:variable> > > <xsl:copy-of select="xx:node-set()/*/namespace::*"/> There's also the dummy-attribute approach, where you create ignorable attributes in the namespace: <xsl:template match="elem"> <xsl:element name="{@name}" namespace="{ns[@type = 'own']}"> <xsl:for-each select="ns[@type = 'extra']"> <xsl:attribute name="{@prefix}:dummy" namespace="{.}" /> </xsl:for-each> </xsl:element> </xsl:template> Given: <elem name="myElem"> <ns type="own" prefix="">http://www.domain1.org/ns</ns> <ns type="extra" prefix="pre2">http://www.domain2.org/ns</ns> <ns type="extra" prefix="pre3">http://www.domain3.org/ns</ns> </elem> Produces: <myElem xmlns="http://www.domain1.org/ns" xmlns:pre2="http://www.domain2.org/ns" xmlns:pre3="http://www.domain3.org/ns" pre2:dummy="" pre3:dummy="" /> Of course if you're not happy with the dummy attributes being present, then you have to post-process to get rid of them, which you can do with the identity template plus: <xsl:template match="@*[local-name() = 'dummy']" /> And to do that in one stylesheet you require a node-set() extension. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Adding namespace nodes qu, Michael Kay | Thread | [xsl] RE: Adding namespace nodes qu, Manos Batsis |
Re: [xsl] Correct syntax for removi, Ahmad J Reeves | Date | [xsl] Sablotron & xselerator, Antonio Padilla |
Month |