This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

how to replace line-feeds with space?


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]