Re: [xsl] default or no namespace

Subject: Re: [xsl] default or no namespace
From: ac <ac@xxxxxxxxxxxxx>
Date: Wed, 29 Dec 2010 13:44:12 -0500
Hi Andrew,

You wrote: "It's up to you, I prefer the moded approach"

And you are right, it is up to each to decide.

OTOH, after careful consideration, and some pain, and although the <element> namespace attribute is quite handy, I would agree with you that the "moded" approach is typically preferable, but not so much for a matter of taste, but because, in any non trivial case, it is much better. A typical example may be an html/xhtml page that is generated by sections and later assembled, where either every section and element may require determining the proper namespace to apply, as well as the way to apply it (e.g. prefix, default, none), spreading the condition (e.g. $cond) requirement in the code and possibly different stylesheets. An additional (e.g. moded) pass makes everything a lot more straightforward and flexible.

You were right, but a bit more info may have saved some pain. OTOH, there is no clear proof the the information recipient would have appreciated and benefited from the info as much as from the pain.)

Thank you.

Regards,
ac




On 28 December 2010 14:59, ac<ac@xxxxxxxxxxxxx> wrote:
Hi Andrew, All,

Interesting. I think that I need a little more though.

Does it mean that I should do something like:

<xsl:variable name="page">
<html>
        ...
</html>
</xsl:variable>
<xsl:choose>
<xsl:when test="$cond">
<xsl:apply-templates mode="put-in-xhtml-ns" select="$page"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select=$page"/>
</xsl:otherwise>
</xsl:choose>
...
<xsl:template mode="put-in-xhtml-ns" match="*">
<xsl:element name="{QName('http://www.w3.org/1999/xhtml', local-name(.))}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates mode="#current"/>
</xsl:copy>
</xsl:template>
Yes that's pretty much it.  Instead of the QName constructor, you
could've used the namespace attribute on xsl:element. (also im
assuming the missing closing</xsl:element>  is a typo)


Why not something simpler as just
<xsl:element name="
  {QName(if ($cond) then 'http://www.w3.org/1999/xhtml' else '', 'html')}">
  ...
</xsl:element>
It's up to you, I prefer the moded approach.

Current Thread