Re: [xsl] Re: xsl:namespace

Subject: Re: [xsl] Re: xsl:namespace
From: Jesper Tverskov <jesper.tverskov@xxxxxxxxx>
Date: Sun, 22 Feb 2009 12:28:30 +0100
Thanks.

I have made a stylesheet example illustrating MK's additional use
case. Below, xsl:namespace is used to transfer namespace declarations
from children elements to outermost element in output. This is only
for cosmetic reasons, to clean things up, but very nice.

I have a feeling that for this use case it is only necessary for
dynamically created namespaces.

It seems to me that as long as we can put the proper namespace
declarations in the xsl:stylesheet element, they always show up in the
outermost element of output unless we exclude them?

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
    <xsl:output indent="yes"/>
    <xsl:param name="ns-prefix" select="'somePrefix'"/>
    <xsl:param name="ns-namespace" select="'someNamespace'"/>
    <xsl:template name="start" match="/">
        <catalog>
            <xsl:namespace name="{$ns-prefix}" select="$ns-namespace"/>
            <xsl:element name="{$ns-prefix}:product"
namespace="{$ns-namespace}"/>
            <xsl:element name="{$ns-prefix}:product"
namespace="{$ns-namespace}"/>
        </catalog>
    </xsl:template>
</xsl:stylesheet>

Cheers,
Jesper Tverskov

http://www.xmlkurser.dk
http://www.xmlplease.com

Current Thread