xsl-list
[Top] [All Lists]

[xsl] default or no namespace

2010-12-28 01:01:51
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 cannot output a namespace node for the default namespace when the element is in no namespace <!-- or <xsl:namespace name="xmlns">http://www.w3.org/1999/xhtml</xsl:namespace>, but then xmlns name is not acceptable, or even <xsl:namespace>http://www.w3.org/1999/xhtml</xsl:namespace>, but the name attribute is required -->
</if>
 ...
</html>

The following may also have been nice, if it created a namespace node rather than an xmlns attribute:
<html xmlns="if ($cond) then 'http://www.w3.org/1999/xhtml' else '' ">
    ...
</html>


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:call-template name="html-body">
<xsl:with-param name="xxx" select="abc"/>
                ...
</xsl:call-template>
</html>
</xsl:when>
<xsl:otherwise>
<html>
<xsl:call-template name="html-body">
<xsl:with-param name="xxx" select="abc"/>
                ...
</xsl:call-template>
</html>
</xsl:otherwise>
</xsl:choose>

But, especially as this would seem like a common case, I am sincerely hoping that there is a better way.
How should this be better handled?

Regards,
ac


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--