[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Problem with namespaces when transforming one namespace to another.


Subject: [xsl] Problem with namespaces when transforming one namespace to another.
From: "Sal Mangano" <smangano@xxxxxxxxxx>
Date: Mon, 27 May 2002 12:15:18 -0400

There is something I am not understanding about the behavior of
namespaces.

Imagine I have the following XML:

<foo:someElement xmlns:foo="http://www.somewhere.com/namespace/foo"
xmlns:doc="http://www.somewhere.com /namespace/doc">
  <foo:aChild>
    <foo:aGrandChild/>
    <foo:aGrandChild>
      <doc:doc>This documentation should not be removed or altered in
any way.</doc:doc>
    </foo:aGrandChild>
  </foo:aChild>
</foo:someElement>

And I want to change all elements in the foo namespace to a bar
namespace but leave all other elements untouched. . I use the following
stylesheet.


<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:foo="http://www.somewhere.com/namespace/foo"
 xmlns:bar="http://www. somewhere.com/namespace/bar">

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

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

<xsl:template match="foo:*">
  <xsl:element name="bar:{local-name()}">
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>	

</xsl:stylesheet>


The output is:

<?xml version="1.0" encoding="UTF-8"?>
<bar:someElement xmlns:bar="http://www.somewhere.com/namespace/bar">
   <bar:aChild>
      <bar:aGrandChild/>
      <bar:aGrandChild>
         <doc:doc xmlns:doc="http:/www.somewhere.com/namespace/doc"
xmlns:foo="http:/www.somewhere.c
om/namespace/foo">This documentation should not be removed or altered in
any way.</doc:d
oc>
      </bar:aGrandChild>
   </bar:aChild>
</bar:someElement>

Which is fine except that the doc element retains the foo namespace
which seems to server no purpose anymore and I would prefer to be
stripped.

Suggestions?
 



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



Current Thread