Xslt and multi-line text (Sitecore)
I have a field in item (multi-line tex开发者_如何学JAVAt) 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?
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>
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
精彩评论