[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

how to replace line-feeds with space?

Subject: how to replace line-feeds with space?
From: Chad Small <chad.small@xxxxxxxxxxxxxxxxxx>
Date: Tue, 14 Nov 2000 22:06:27 -0600
replace line
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 &#10;
or &#x0A;

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, '&#10;')">
        <xsl:value-of select="substring-before($text, '&#10;')"/>
        <xsl:text> </xsl:text>
        <xsl:call-template name="break">
          <xsl:with-param name="text"
select="substring-after($text,'&#10;')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$text"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="/">
    <xsl:text> &#10;</xsl:text>
    <xsl:text>SRC_UNIQUE_ID: </xsl:text><xsl:value-of
select="CONTENT/SOURCE_UNIQUE_ID"/><xsl:text/><xsl:text>&#10;</xsl:text>
    <xsl:text>TITLE: </xsl:text><xsl:value-of
select="CONTENT/TITLE"/><xsl:text>&#10;</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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.