[Home] [By Thread] [By Date] [Recent Entries]
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
|

Cart



