开发者

Xslt and multi-line text (Sitecore)

开发者 https://www.devze.com 2022-12-18 20:52 出处:网络
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 out

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,'&#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>


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
0

精彩评论

暂无评论...
验证码 换一张
取 消