Re: [xsl] default or no namespace

Subject: Re: [xsl] default or no namespace
From: Andrew Welch <andrew.j.welch@xxxxxxxxx>
Date: Tue, 28 Dec 2010 10:56:13 +0000
On 28 December 2010 07:02, ac <ac@xxxxxxxxxxxxx> wrote:
> Hi,
>
> With XSLT2, I have an element that can be either in no namespace or in the
> default namespace, based on some condition, as in
> <html>
>   ...
> </html>
>
> or
> <html xmlns="http://www.w3.org/1999/xhtml";>
>   ...
> </html>
>
> Without success, I tried things like:
> <html>
> <if test="$cond">
> <xsl:namespace name="">http://www.w3.org/1999/xhtml</xsl:namespace>, but
...
> I understand that I could probably put the body of the html element in a
> template (e.g. html-body), define all the (tons of) required parameters,
and
> do something like:
>
> <xsl:choose>
> <xsl:when test="$cond">
> <html xmlns="http://www.w3.org/1999/xhtml";>
...
> <xsl:otherwise>
> <html>

You can't do either because the namespace is applied at the xml level,
not at the xslt level.  In other words, the default namespace would
only be changed for the children of <html> in the xml that is your
stylesheet, not in the constructed result.

The usual technique is to have an identity transform as the last step
to put the elements into the xhtml namespace (use modes if you want to
keep it all in a single transform).


--
Andrew Welch
http://andrewjwelch.com

Current Thread