This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
how to replace line-feeds with space?
- To: "Xsl-List (E-mail 2)" <xsl-list at mulberrytech dot com>
- Subject: how to replace line-feeds with space?
- From: Chad Small <chad dot small at definityhealth dot com>
- Date: Tue, 14 Nov 2000 22:06:27 -0600
- Reply-To: xsl-list at mulberrytech dot com
I found some info on dpawson's basic trouble-shooting under the Replace
link,
but can't seem to make the transformation work.
If I have some xml like this:
<CONTENT>
<SOURCE_ID>1</SOURCE_ID>
<SOURCE_UNIQUE_ID>5</SOURCE_UNIQUE_ID>
<TITLE>Hello<LF> world?</TITLE>
<CONTENT>
And want to replace all linefeeds in the Title element with a single space
character.
The linefeed that I've shown as <LF> would actually be represented by
or 

My attempt at the xslt was:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:strip-space elements = "*"/>
<xsl:template match="TITLE/text()">
<xsl:call-template name="break"/>
</xsl:template>
<xsl:template name="break">
<xsl:param name="text" select="."/>
<xsl:choose>
<xsl:when test="contains($text, ' ')">
<xsl:value-of select="substring-before($text, ' ')"/>
<xsl:text> </xsl:text>
<xsl:call-template name="break">
<xsl:with-param name="text"
select="substring-after($text,' ')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="/">
<xsl:text> </xsl:text>
<xsl:text>SRC_UNIQUE_ID: </xsl:text><xsl:value-of
select="CONTENT/SOURCE_UNIQUE_ID"/><xsl:text/><xsl:text> </xsl:text>
<xsl:text>TITLE: </xsl:text><xsl:value-of
select="CONTENT/TITLE"/><xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>
As my final result I am trying to get:
SRC_UNIQUE_ID: 5
TITLE: Hello World? <--------------no linefeed this time
Thank-you for your time. Any help would be greatly appreciated.
thanks,
chad.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list