Showing posts with label HTML. Show all posts
Showing posts with label HTML. Show all posts

Sunday, June 01, 2008

SharePoint Designer: Show Line Break for Multi Text (Plain Text)

If you have Multiline type column and set it with "Plain Text", you might have difficulty to show it using Data View (that is added using SharePoint Designer) for the content that has a line break. It will show as a single line. If you view the HTML Source of the page, the line-break character is actually printed there. It's just that HTML will not interpret such white-space character as line break.

There're 2 ways to overcome this issue:

1. Wrap your <xsl:value-of select="@Column_Name" escaping="yes"></xsl:value-of>using <pre>. However, you will lose the text-wrap functionality, since most browser will render <pre> as it is, no line break means no line break. This maybe a no-go to this solution.

2. Using xslt functionality to change all line break to.For example your original text is:
<xsl:value-of select="@Column_Name" escaping="yes"></xsl:value-of>

Replace it to:
<xsl:call-template name="breakitemdesc"></xsl:call-template>

Add below to the beginning of the other <xslt:template> or after </xslt:template> of the section:

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