Re: [xslt] Suppressing namespace attributes



Hi,

I found the only reliable way to remove unwanted namespaces was to pass
the result set through a template....
e.g.

<xsl:template match="/">
    <xsl:variable name="myUnDesiredOutput">
        <xsl:apply-templates select="..."/>
    </xsl:variable>

    <xsl:apply-templates select="exsl:node-set($myUnDesiredOutput)"
mode="copy-no-namespace"/>
</xsl:template>

<xsl:template match="*" mode="copy-no-namespace">
    <xsl:element name="{name()}"> <!-- This removes the namespace -->
        <xsl:copy-of select="@*"/>
        <xsl:apply-templates select="*|text()|comment()"
mode="copy-no-namespace"/>
    </xsl:element>
</xsl:template>
    
<xsl:template match="text()|comment()" mode="copy-no-namespace">
    <xsl:copy>
        <xsl:copy-of select="@*"/>
        <xsl:apply-templates select="*|text()|comment()"
mode="copy-no-namespace"/>
    </xsl:copy>
</xsl:template>

Nick

-----Original Message-----
From: xslt-bounces gnome org [mailto:xslt-bounces gnome org] On Behalf
Of Hans Guijt
Sent: 06 June 2007 18:21
To: xslt gnome org
Subject: Re: [xslt] Suppressing namespace attributes

Daniel Veillard wrote:
>  the namespace prefix you define could be used by constructs outside 
>of the structure and the XSLT processor has absolutely no way to guess 
>whether this may impact the semantic of the output data. So as a rule 
>XSLT-1.0 requires all namespaces in scope to be copied. Declare the 
>namespace as an extension namespace that's the only way to avoid the 
>copying.

I have tried adding extension-element-prefixes="ur" to my
<xsl:stylesheet> element, but unfortunately that seems to have the same
result as Brett's
suggestion: the xmlns:ur attribute moves from the <section> element to
the <para> element.

Combining the two solutions also fails to yield the desired result ;-)


Regards,

Hans Guijt



_______________________________________________
xslt mailing list, project page http://xmlsoft.org/XSLT/ xslt gnome org
http://mail.gnome.org/mailman/listinfo/xslt


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]