1

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?

andy svar
  • 11
  • 2
  • Your requirements are confusing. Are the HTML tags included in your 250 character count? What would an HTML-aware substring function do? Would it only limit text within tags? Would it strip off attributes? – Peter Jacoby Feb 12 '10 at 21:25
  • No, tags are not included in the 250 chars count, just plain text. The text is intertwined within regular HTML formatting tags. If the @Body attribute contains Text sample sample and the limit is 10 chars (counting only plain text), the result should be Text sampl. So I need to truncate HTML formatted text in a smart way to produce still valid HTML. Hope this made my issue clear :-) – andy svar Feb 13 '10 at 19:07

2 Answers2

0

I found a very simple solution for this,try this instead!

<xsl:value-of select="substring(@Body, 1, 250 + string-length(substring-before(substring(@Body, 250),' ')))" />
jose vega
  • 11
  • 1
0

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
  • 935
  • 1
  • 7
  • 13