views:

326

answers:

2

I have a field in item (multi-line text) which i output in my xslt rendering. The problem is that carrigae return are not shown in my output - what do i need to do to make my xslt output show the carrigae returns?

A: 

A carriage return in XML source is ignored as whitespace. (Really, all consecutive whitespace characters are condensed to one space.) However, perhaps one of these will work instead of a plain carriage return?

       <xsl:text>This text has
a newline</xsl:text>

Or

This text has&#10;a newline
Patrick Szalapski
The problem is that a user enters text into a Text box - this is saved as a "Text-box multiple" (in sitecore terms). Then when the text is displayed all carriage returns are a no-show. It is not possible for me to get the user to enter special caracters to do a carriage return ;-)
cJockey
+2  A: 

Use this template to substitude newlines:

<xsl:template name="br">
    <xsl:param name="text"/>
    <xsl:choose>
        <xsl:when test="contains($text,'&#xa;')">
            <xsl:value-of select="substring-before($text,'&#xa;')"/>
            <br/>
            <xsl:call-template name="br">
                <xsl:with-param name="text">
                    <xsl:value-of select="substring-after($text,'&#xa;')"/>
                </xsl:with-param>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$text"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

And call it upon your text item like this:

<xsl:call-template name="br">
    <xsl:with-param name="text" select="somenode/mytext"/>
</xsl:call-template>
aefxx
Works like a charm - thx!
cJockey
You're welcome :D
aefxx