Unused namespaces (was RE: [xsl] transform mixing up namespaces)

Subject: Unused namespaces (was RE: [xsl] transform mixing up namespaces)
From: "Gareth Sylvester-Bradley" <gareth.sbradley@xxxxxxxxxxxxxxx>
Date: Thu, 24 May 2001 15:01:24 +0100
> I am using Xalan 1.2.  (Another behavior that is annoying, but correct as
> far as I know, is that Xalan will create result documents with unused
> namespace declarations.  See an example at the bottom of this email.)

This seems to be the specified behaviour. If nodes in the source document
have associated namespace nodes (which they do in your case) then xsl:copy
and xsl:copy-of will copy the namespace nodes even if they are "unused". I
guess you can see the point: how is the XSLT processor to know that the
namespace is unused (e.g. in attribute values like XPath expressions, or
elsewhere)?

However, I wanted the same behaviour as you do. I ended up using xsl:element
and xsl:attribute instead. This means adding the following templates:

<xsl:template mode="copy-of" match="*">
  <xsl:element name="{name()}" namespace="{namespace-uri()}">
    <xsl:apply-templates mode="copy-of"
        select="@*|*|text()|processing-instruction()|comment()" />
  </xsl:element>
</xsl:template>

<xsl:template mode="copy-of" match="@*">
  <xsl:attribute name="{name()}" namespace="{namespace-uri()}">
    <xsl:value-of select="." />
  </xsl:attribute>
</xsl:template>

<xsl:template mode="copy-of"
match="text()|processing-instruction()|comment()">
  <xsl:copy />
</xsl:template>

and then where I previously had xsl:copy-of using:

  <xsl:apply-templates mode="copy-of" select="..." />

instead!


If anybody's got a better solution...

Thanks
-- Gareth




*************************************************************************
The information contained in this message or any of its
attachments may be privileged and confidential and intended 
for the exclusive use of the addressee. If you are not the
addressee any disclosure, reproduction, distribution or other
dissemination or use of this communication is strictly prohibited
**************************************************************************

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


Current Thread