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 a newline
Patrick Szalapski
2010-02-03 23:21:25
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
2010-02-03 23:31:10
+2
A:
Use this template to substitude newlines:
<xsl:template name="br">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($text,'
')">
<xsl:value-of select="substring-before($text,'
')"/>
<br/>
<xsl:call-template name="br">
<xsl:with-param name="text">
<xsl:value-of select="substring-after($text,'
')"/>
</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
2010-02-03 23:34:15