Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

preserving line breaks and HTML tags in text

1,080 views
Skip to first unread message

Paul

unread,
Feb 28, 2002, 12:58:10 PM2/28/02
to
I've got an XSLT which will preserve line breaks in the output HTML so the
user doesn't have to specify <br> or <p> to keep paragraphs and line breaks.

The problem is I want to be able to put <b> / <i> tags straight into the
text of the document and have them preserved when it is transformed into
HTML.

I've tried <xsl:copy> and <xsl:copy-of> but when the text is then put
through the <xsl:template> which preserves the line breaks the HTML tags are
stripped out.

Does anyone know how to preserve the HTML tags and preserve the line breaks?

all help appreciated,

Paul
--
http://www25.brinkster.com/dazzle
Make a donation to Open Source support and development:
http://www.25.brinkster.com/dazzle#donations
The Jesus Christ Cafe - an ebook not a religion -
http://www.nospine.net/default.asp?ShowTitle=0044-00194-001


Orhan Teke

unread,
Mar 1, 2002, 8:00:43 AM3/1/02
to
Paul,

Try this:

<xsl:value-of select="myHTMLTExt" disable-output-escaping="yes"/>

Orhan

"Paul" <dazz...@hotmail.com> wrote in message
news:#D2EbGIwBHA.1592@tkmsftngp07...

Julian F. Reschke

unread,
Mar 1, 2002, 8:19:52 AM3/1/02
to
"Orhan Teke" <o.teke@[removethis]logan.nl> schrieb im Newsbeitrag
news:u5b6UDSwBHA.2592@tkmsftngp04...

> Paul,
>
> Try this:
>
> <xsl:value-of select="myHTMLTExt" disable-output-escaping="yes"/>

Don't do that. It's not portable.

Julian F. Reschke

unread,
Mar 1, 2002, 8:20:59 AM3/1/02
to
"Paul" <dazz...@hotmail.com> schrieb im Newsbeitrag
news:#D2EbGIwBHA.1592@tkmsftngp07...

> I've got an XSLT which will preserve line breaks in the output HTML so the
> user doesn't have to specify <br> or <p> to keep paragraphs and line
breaks.
>
> The problem is I want to be able to put <b> / <i> tags straight into the
> text of the document and have them preserved when it is transformed into
> HTML.
>
> I've tried <xsl:copy> and <xsl:copy-of> but when the text is then put
> through the <xsl:template> which preserves the line breaks the HTML tags
are
> stripped out.
>
> Does anyone know how to preserve the HTML tags and preserve the line
breaks?
>
> all help appreciated,

It depends on your XSLT. You should start with an indentity transformation
(there's an example in the XSLT spec), then add the specific template for
your text formatting.

Paul

unread,
Mar 1, 2002, 8:33:52 AM3/1/02
to
Here is the XSLT I am using to preserve the line breaks:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="ISO-8859-1"
omit-xml-declaration="yes" indent="yes" />

<xsl:template match="//info">
<h2>
<xsl:value-of select="title" />
</h2>

<br />
</xsl:template>

<xsl:template match="main">
<xsl:call-template name="cr">
<xsl:with-param name="word">
<xsl:value-of select="." />
</xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template name="cr">
<xsl:param name="word" />

<xsl:choose>
<xsl:when test="contains($word,'
')">
<xsl:value-of select="substring-before($word,'
')" />

<br />

<xsl:call-template name="cr">
<xsl:with-param name="word" select="substring-after($word,'
')" />
</xsl:call-template>
</xsl:when>

<xsl:otherwise>
<xsl:value-of select="$word" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="/">
<xsl:apply-templates select="//story" />
</xsl:template>
</xsl:stylesheet>


and here is the XML it transforms:

<?xml version="1.0"?>
<story>
<info>
<title>a title</title>

<author>the author</author>

<description>a description</description>
</info>

<main>
This is some text and this should be <i>italic</i> and this should be
<b>bold</b>
and this is a new line

and this is a paragraph
</main>
</story>

The line breaks are transformed into <br/> tags but in the transoformation
it strips out the HTML tags even when trying to use <xsl:copy> /
<xsl:copy-of>

All help appreciated

Paul

Julian F. Reschke

unread,
Mar 1, 2002, 8:43:30 AM3/1/02
to
Try:

<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>

<xsl:template match="text()">


<xsl:call-template name="cr">
<xsl:with-param name="word">
<xsl:value-of select="." />
</xsl:with-param>
</xsl:call-template>
</xsl:template>

and remove the "main" template.


"Paul" <dazz...@hotmail.com> schrieb im Newsbeitrag

news:#958ZXSwBHA.428@tkmsftngp04...

Paul

unread,
Mar 1, 2002, 10:17:14 AM3/1/02
to
It worked ! Cheers.

Thanks,

Paul
--


http://www25.brinkster.com/dazzle
Make a donation to Open Source support and development:
http://www.25.brinkster.com/dazzle#donations
The Jesus Christ Cafe - an ebook not a religion -
http://www.nospine.net/default.asp?ShowTitle=0044-00194-001

"Julian F. Reschke" <julian....@nospam-greenbytes.de> wrote in message
news:#cEv9bSwBHA.2516@tkmsftngp04...

0 new messages