Line breaks in long text fields

Sep 28, 2010 at 3:50 PM

This is basically a text-replace function...

<xsl:template name="add-line-breaks">
   <xsl:param name="string"/>
   <xsl:choose>
      <xsl:when test="contains($string, '&#xA;')">
         <xsl:value-of select="substring-before($string, '&#xA;')" disable-output-escaping="yes"/>
         <br />
         <xsl:call-template name="add-line-breaks">
            <xsl:with-param name="string"
                            select="substring-after($string, '&#xA;')" />
         </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
         <xsl:value-of select="$string" disable-output-escaping="yes" />
      </xsl:otherwise>
   </xsl:choose>
</xsl:template>

Alex

Coordinator
Sep 29, 2010 at 2:17 AM

Alex:

Can you explain a bit how you used this template? I can see how it works, but I'm struggling a little with the use case.

Thanks a lot for pitching it into the project!

M.

Sep 29, 2010 at 9:47 AM

Hi Marc,

Simple. When you have a List with a field that is "Multiple lines of text" and is set to Plain Text, there is no HTML encoding in the text that's saved. This template restores the line breaks when the field is shown in a DVWP.

Alex