[xsl] RE: Setting Namespace on Generated xsl:stylesheet Element

Subject: [xsl] RE: Setting Namespace on Generated xsl:stylesheet Element
From: "Roger L. Cauvin" <roger@xxxxxxxxxx>
Date: Tue, 26 Jan 2010 09:12:37 -0600
>> To generate the xsl:stylesheet element in B.xsl, I have the
>> following excerpt in A.xsl:
>>
>> <xsl:element name="xsl:stylesheet">
>> <xsl:namespace name="atom">http://www.w3.org/2005/Atom</xsl:namespace>
>> <xsl:attribute name="version">1.0</xsl:attribute>
>> ...
>> </xsl:element>
>
> You don't need to be that elaborate, just use namespace alias:
>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
> xmlns:xslo="dummy">
>
> <xsl:namespace-alias stylesheet-prefix="xslo" result-prefix="xsl"/>
>
> <xsl:template ....
>    <xslo:stylesheet version="1.0"
>                     xmlns:atom="http://www.w3.org/2005/Atom";>
>    .....
>    </xslo:stylesheet>
> </xsl:template>
>
> This uses a non-XSLT namespace in the template rule but the
> XSLT namespace in the result tree.

Thanks, Ken.  This solution worked flawlessly for me.

Stylistically, I prefer to use <xsl:element> to generate elements, but I can
definitely live with this solution.

--
Roger L. Cauvin
@rcauvin (Twitter)
cauvin.blogspot.com (blog)

Current Thread