开发者

Truncating HTML attribute value in SharePoint DataFormWebPart

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 awa开发者_运维百科re.

Any ideas, please?


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>


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),' ')))" />
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜