Re: [xsl] MSXML, xsl:copy, XML Output and BR tags.

Subject: Re: [xsl] MSXML, xsl:copy, XML Output and BR tags.
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Fri, 6 Apr 2001 08:59:01 +0100
Hi Paul,

> I realise this is probably parser implementation specific. Any ideas
> how can I make the XSL transformation leave the <br /> as it is?? I
> really do not want to use <xsl:output method="html"> since I wish to
> have the data preserved as XHTML for later manipulation...

I tried a template like this with MSXML3:

<xsl:template match="br">
   <xsl:copy><xsl:copy-of select="@*|node()" /></xsl:copy>
   <xsl:copy><xsl:copy-of select="@*" /></xsl:copy>
   <xsl:copy-of select="." />
   <xsl:element name="br" />
   <br />

This produced:

<br />
<br />
<br />
<br />

So it appears that it's only by trying to add some content in an
xsl:copy that you get open-tag/close-tag syntax.

What I'd recommend is either copying everything in the subtree you
want to copy with xsl:copy-of (which is quicker than doing it
recursively anyway) or adding a template that matches *empty* elements
and doesn't try to copy any content into them:

<xsl:template match="*[not(node())]">
   <xsl:copy><xsl:apply-templates select="@*" /></xsl:copy>

In some ways you're lucky - other processors don't have a space before
the / in the br element, which is another syntax that confuses HTML
browsers, and has to be worked around by adding an attribute as
Wendell suggested. But these problems are why there's a need for an
'xhtml' output method (as in Saxon), which might come along in XSLT
2.0 and is something I intend to include in EXSLT when I have a few

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread