|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Problem with namespaces when transforming one namespac
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
|
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
|

Cart








