Re: [xsl] Namespaces and the identity transform

Subject: Re: [xsl] Namespaces and the identity transform
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 29 Oct 2002 18:19:27 +0000
Hi James,

> How can I design an identity transform that applies the default
> namespace to the output? I prefer not to have to restructure my
> input, and I want all output nodes to use the strict xhtml
> namespace. I substituted the above identity transform with the
> following and this seems to produce the correct output, but is this
> the most efficient way of doing it?
> <xsl:template match="*">
>         <xsl:element name="{name()}">
>                 <xsl:apply-templates select="@*|node()"/>
>         </xsl:element>
> </xsl:template>
> <xsl:template match="@*">
>         <xsl:attribute name="{name()}">
>                 <xsl:value-of select="."/>
>         </xsl:attribute>
> </xsl:template>

If this is the only processing that you're doing, you don't have to
worry about having a separate template for the attributes; you can
just do:

<xsl:template match="*">
  <xsl:element name="{local-name()}">
    <xsl:copy-of select="@*" />
    <xsl:apply-templates />

Note that I've used local-name() rather than name(); that's just in
case someone includes a prefix on the elements in your source



Jeni Tennison

 XSL-List info and archive:

Current Thread