views:

385

answers:

2

Hello,

I'm using DataFormWebPart to display all announcements in the SharePoint site collections. It uses SPDataSouce with DataSourceMode set to CrossList and it works OK. The text of the announcement comes from the XML attribute:

<xsl:value-of disable-output-escaping="yes" select="@Body" />

Now I need to limit this text to, say, 250 characters. Of course, I cannot truncate it as a simple string as it could produce invalid HTML. I needed something like ddwrt:Limit but HTML aware.

Any ideas, please?

A: 

I think you want to display 250 characters in the page, please use this script

<xsl:if test="string-length(@Body) &lt;= 250">

  <xsl:value-of select="@Body"/>
    </xsl:if>
    <xsl:if test="string-length(@Body) &gt; 250">



  <xsl:value-of select="substring(@Body,0,250)"/>....

    </xsl:if>
Hojo
A: 

This question has been asked before here. Maybe the answer helps you.

Selecting an abstract of n words including HTML tags with XSLT

Tomalak