Re: [xsl] Removing line breaks without normalize-space()

Subject: Re: [xsl] Removing line breaks without normalize-space()
From: "Spencer Tickner" <spencertickner@xxxxxxxxx>
Date: Tue, 19 Sep 2006 10:05:06 -0800
I believe something like this will work

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:variable name="cr"><xsl:text>
</xsl:text></xsl:variable>
<xsl:template match="/">
	<xsl:apply-templates/>
</xsl:template>

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

<xsl:template match="text()">
<xsl:value-of select="translate(., $cr, '')"/>
</xsl:template>

</xsl:stylesheet>

On 9/19/06, Mark Peters <flickrmeister@xxxxxxxxx> wrote:
Hi,

Is there any way to remove line breaks without deleting the whitespace
in-between elements? For example, suppose you started with the
following XML:

<paragraph>
        <sentence>Some words are <i>italicized</i> and some words are in
<b>bold</b>.</sentence>
        <sentence>Some words are <u>underlined</u>.</sentence>
</paragraph>


I'd like to remove the line breaks, but otherwise retain any existing whitespace between elements, resulting in the following XML:

<paragraph><sentence>Some words are <i>italicized</i> and some words
are in <b>bold</b>.</sentence><sentence>Some words are
<u>underlined</u>.</sentence></paragraph>

I'm trying to avoid sentences whose contents run together when I
process the text.

Thanks!

Mark

--

Mark Peters
Senior Technical Writer
Saba Software

Current Thread