Re: [xsl] break line using stylesheet

Subject: Re: [xsl] break line using stylesheet
From: Jon Gorman <jonathan.gorman@xxxxxxxxx>
Date: Fri, 21 Oct 2005 08:47:49 -0500
On 10/21/05, Vincent Lapointe <lapointe_vincent_1975@xxxxxxxxxxx> wrote:
> Hi all,
> I'm pretty new to xml/xsl/html files and have the following problem: I'm
> using xml and xsl to generate a simple html file.

In XML files elements that are empty still need a closing tag or need
to use the empty tag symbols...

ie <br> should be either <br /> or <br></br>.  You don't have a
well-formed XML file.  If it's not an element, and you're doing
character escaping it is just text.  If you need to convert sgml to
xml there are tools out there (drawing a blank, but I'm pretty sure
James Clark has one. trang?  )  Of course, if it's just sgml html you
can convert it using tidy.


> the same output as internet explorer. In internet explorer the break lines
> appear as html break lines, but in mozilla the break lines appear as
> litteral string "<br>".

You've done disable-output-escaping (doe), so that probably causing
the problem.  It's not required for a processor to implement.  (It's
described more in 16.4 of the XSLT 1.0 spec).

> - I setted the disable-output-escaping attribute to "yes" and "no", and it
> didn't work with above combination...

Again, why the heck are you using doe?

> - I added the <xsl:preserve-space elements="text"/> in my xsl file and it
> didn't work with above combination...

Considering that <br> isn't  whitespace that certainly wouldn't work.
How you are treating it is the opposite of whitespace, ie right now
it's pure character data.  But for it to be really useful, you need to
treat it as an element.  Remember XSLT doesn't treat any xml input in
a special way.  It has no idea that <br> is supposed to be
"whitespace".

> Any idea? Thanks for your comments...
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> <xsl:output method="html" indent="yes" encoding="iso-8859-1"/>
> <xsl:template match="root">
> <html>
> <body>
> <xsl:apply-templates select="text"/>
> </body>
> </html>
> </xsl:template>
> <xsl:template match="text">
> <div>
> <xsl:value-of select="." disable-output-escaping="yes"/>
> </div>
> </xsl:template>
> </xsl:stylesheet>

Why the xsl:value-of select="." disable-output-escaping="yes"?

Why not just do something like the following example?

> <xsl:template match="text">
> <div>
<xsl:apply-templates />
> </div>
> </xsl:template>

<xsl:template match="br">
<br />
</xsl:template>

That way the built-in rules will catch the various text nodes, and the
br will work once you actually have well-formed XML.

These are all FAQs, and you might want to look through some tutorials
and the FAQ.


Jon Gorman

Current Thread