[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Hi Andrew, All,
Interesting. I think that I need a little more though.
Does it mean that I should do something like:
and either (please confirm which, if any):
What would be best?
Thank you.
Re: [xsl] default or no namespace
Subject: Re: [xsl] default or no namespace From: ac <ac@xxxxxxxxxxxxx> Date: Tue, 28 Dec 2010 09:59:27 -0500 |
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>
and either (please confirm which, if any):
<xsl:template mode="put-in-xhtml-ns" match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates mode="#current"/> </xsl:copy> </xsl:template>
<xsl:template mode="put-in-xhtml-ns" match="html"> <xsl:element name="html"> <xsl:namespace name="xhtml">http://www.w3.org/1999/xhtml</xsl:namespace> <xsl:copy-of select="@*"/> <xsl:apply-templates mode="#current"/> </xsl:copy> </xsl:template>
or <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>
Why not something simpler as just <xsl:element name=" {QName(if ($cond) then 'http://www.w3.org/1999/xhtml' else '', 'html')}"> ... </xsl:element>
What would be best?
Thank you.
Regards, ac
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).
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] default or no namespace, Andrew Welch | Thread | Re: [xsl] default or no namespace, Andrew Welch |
Re: [xsl] default or no namespace, Piet van Oostrum | Date | Re: [xsl] default or no namespace, Andrew Welch |
Month |