PranasLu's Blog

2011-01-13

Tip&Trick: Xslt and multi-line text in HTML, WordML

Filed under: Programming — Tags: , , , — pranaslu @ 10:19

The code below shows how to convert linebreak to <br/>. You can easily adopt this template to convert linebreak to anything else.

Use this template to substitude newlines in HTML:

<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>

Source: http://stackoverflow.com/questions/2196258/xslt-and-multi-line-text-sitecore

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: