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) <= 250">
<xsl:value-of select="@Body"/>
</xsl:if>
<xsl:if test="string-length(@Body) > 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),' ')))" />
精彩评论