This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Removing namespaces from source document (long)


"Stephen Ng" <stephen dot ng at verizon dot net> wrote:
> I have the feeling this is a newbie faq thing, but I'm still confused

> after doing a bit of searching this weekend so I'm posting....
> 
> I have some (unused) namespace declarations in my source xml document

> that I want to banish.

This is not difficult at all. The following stylesheet:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output omit-xml-declaration="yes"/>

  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*" />
    </xsl:copy>
  </xsl:template>

  <xsl:template match="*">
    <xsl:element name="{name()}" namespace="{namespace-uri(.)}">
      <xsl:copy-of select="namespace::*[name() != 'bad-ns']" />
      <xsl:apply-templates select="node()|@*" />
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>

When applied on your original source xml document:

<root xmlns:good-ns="http://good.com"; xmlns:bad-ns="http://bad.com";>
  <parent color="red">
   <good-ns:child shape="square">
    some text
    </good-ns:child>
  </parent>
</root>


Produces:

<root xmlns:good-ns="http://good.com";>
  <parent color="red">
   <good-ns:child shape="square">
    some text
    </good-ns:child>
  </parent>
</root>


Hope this helped.

Cheers,
Dimitre Novatchev.



__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]