Question : How to Truncate Body Text in SharePoint 2007 RSS Viewer Webpart

I'm using a SharePoint 2007 RSS viewer webpart to pull in blog posts from another site.  Works fine, and it gives me the option to show the feed the title only or to also include the body of the post (the "show feed title and description" option).

The problem is that enabling this option displays the entire body of the post.  Naturally, all of our blog posts are of varying length (and some of them are very long).  I end up having a webpart that scrolls forever when a long post comes up.

I'd like to have this webpart display a consistent size (such as XXX characters) for each post in the feed.  Is there a setting I'm missing?  How do I truncate the feed text that is displayed by the RSS viewer?

I noticed there is an XSLT field in the advanced options of the webpart, wherein you might be able to effect this change using the code.  I'm not a programmer, though.  If anybody has a code change I could use to do that, that would be great.  I'll attach the out of the box code in a .txt file if anybody knows how I should modify it.

Thanks!
 
RSS Viewer Webpart - default XSLT code
 

Answer : How to Truncate Body Text in SharePoint 2007 RSS Viewer Webpart

try this..

it works fine
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema"
               version="1.0" exclude-result-prefixes="xsl ddwrt msxsl rssaggwrt" 
               xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
               xmlns:rssaggwrt="http://schemas.microsoft.com/WebParts/v3/rssagg/runtime"
               xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"
               xmlns:rssFeed="urn:schemas-microsoft-com:sharepoint:RSSAggregatorWebPart"
               xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/"
               xmlns:rss1="http://purl.org/rss/1.0/" xmlns:atom="http://www.w3.org/2005/Atom"
               xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
               xmlns:atom2="http://purl.org/atom/ns#">

    <xsl:param name="rss_FeedLimit">5</xsl:param>
    <xsl:param name="rss_ExpandFeed">false</xsl:param>
    <xsl:param name="rss_LCID">1033</xsl:param>
    <xsl:param name="rss_WebPartID">RSS_Viewer_WebPart</xsl:param>
    <xsl:param name="rss_alignValue">left</xsl:param>
    <xsl:param name="rss_IsDesignMode">True</xsl:param>

        <xsl:template match="rss">
            <xsl:call-template name="RSSMainTemplate"/>
        </xsl:template>

        <xsl:template match="rdf:RDF">
            <xsl:call-template name="RDFMainTemplate"/>
        </xsl:template>

        <xsl:template match="atom:feed">
            <xsl:call-template name="ATOMMainTemplate"/>
        </xsl:template>

        <xsl:template match="atom2:feed">
            <xsl:call-template name="ATOM2MainTemplate"/>
        </xsl:template>

        <xsl:template name="RSSMainTemplate" 
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
            <xsl:variable name="Rows" select="channel/item"/>
            <xsl:variable name="RowCount" select="count($Rows)"/>
            <div class="slm-layout-main" >            
            <div class="groupheader item medium">
                        <a href="{ddwrt:EnsureAllowedProtocol(string(channel/link))}">
                            <xsl:value-of select="channel/title"/>
                        </a>
            </div>            
            <xsl:call-template name="RSSMainTemplate.body">
                <xsl:with-param name="Rows" select="$Rows"/>
                <xsl:with-param name="RowCount" select="count($Rows)"/>
            </xsl:call-template>
            </div>
        </xsl:template>

        <xsl:template name="RSSMainTemplate.body" 
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
            <xsl:param name="Rows"/>
            <xsl:param name="RowCount"/>
            <xsl:for-each select="$Rows">
                <xsl:variable name="CurPosition" select="position()" />
                <xsl:variable name="RssFeedLink" select="$rss_WebPartID" />
                <xsl:variable name="CurrentElement" select="concat($RssFeedLink,$CurPosition)" />
                <xsl:if test="($CurPosition &lt;= $rss_FeedLimit)">
                    <div class="item link-item" >
                            <a 
href="{concat(&quot;javascript:ToggleItemDescription('&quot;,$CurrentElement,&quot;')&quot;)}" >
                                <xsl:value-of select="title"/>
                            </a>
                            <xsl:if test="$rss_ExpandFeed = true()">
                                <xsl:call-template name="RSSMainTemplate.description">
                                    <xsl:with-param name="DescriptionStyle" select="string('display:block;')"/>
                                    <xsl:with-param name="CurrentElement" select="$CurrentElement"/>
                                </xsl:call-template>
                            </xsl:if>
                            <xsl:if test="$rss_ExpandFeed = false()">
                                <xsl:call-template name="RSSMainTemplate.description">
                                    <xsl:with-param name="DescriptionStyle" select="string('display:none;')"/>
                                    <xsl:with-param name="CurrentElement" select="$CurrentElement"/>
                                </xsl:call-template>
                            </xsl:if>
                    </div>                            
                </xsl:if>
            </xsl:for-each>
        </xsl:template>

	<xsl:template name="RSSMainTemplate.description" 
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
            <xsl:param name="DescriptionStyle"/>
            <xsl:param name="CurrentElement"/>
	    <div id="{$CurrentElement}" class="description" align="$rss_alignValue" style="{$DescriptionStyle} text-
align:{$rss_alignValue};">
                <xsl:choose>
                    <!-- some RSS2.0 contain pubDate tag, some others dc:date -->
                    <xsl:when test="string-length(pubDate) &gt; 0">
                        <xsl:variable name="pubDateLength" select="string-length(pubDate) - 3" />
		        <xsl:value-of 
select="ddwrt:FormatDate(substring(pubDate,0,$pubDateLength),number($rss_LCID),3)"/>
                    </xsl:when>
                    <xsl:otherwise>
                    	<xsl:value-of select="ddwrt:FormatDate(dc:date,number($rss_LCID),3)"/>
                    </xsl:otherwise>
                </xsl:choose>

                <xsl:if test="string-length(description) &gt; 0">
                    <xsl:variable name="SafeHtml">
                        <xsl:call-template name="GetSafeHtml">
                            <xsl:with-param name="Html" select="description"/>
                        </xsl:call-template>
                    </xsl:variable>
                     - <xsl:value-of select="$SafeHtml" disable-output-escaping="yes"/>
                </xsl:if>
		    <div class="description">
		        <a href="{ddwrt:EnsureAllowedProtocol(string(link))}">More...</a>
	        </div>
        </div>
        </xsl:template>


        <xsl:template name="RDFMainTemplate" 
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
            <xsl:variable name="Rows" select="rss1:item"/>
            <xsl:variable name="RowCount" select="count($Rows)"/>
            <div class="slm-layout-main" >
            <div class="groupheader item medium">
                <a href="{ddwrt:EnsureAllowedProtocol(string(rss1:channel/rss1:link))}">
                    <xsl:value-of select="rss1:channel/rss1:title"/>
                </a>
            </div>            
            <xsl:call-template name="RDFMainTemplate.body">
                <xsl:with-param name="Rows" select="$Rows"/>
                <xsl:with-param name="RowCount" select="count($Rows)"/>
            </xsl:call-template>
            </div>
        </xsl:template>

        <xsl:template name="RDFMainTemplate.body" 
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
            <xsl:param name="Rows"/>
            <xsl:param name="RowCount"/>
            <xsl:for-each select="$Rows">
                <xsl:variable name="CurPosition" select="position()" />
                <xsl:variable name="RssFeedLink" select="$rss_WebPartID" />
                <xsl:variable name="CurrentElement" select="concat($RssFeedLink,$CurPosition)" />
                <xsl:if test="($CurPosition &lt;= $rss_FeedLimit)">
                    <div class="item link-item" >
                        <a href="{concat(&quot;javascript:ToggleItemDescription('&quot;,$CurrentElement,&quot;')&quot;)}" 
>
                            <xsl:value-of select="rss1:title"/>
                        </a>
                        <xsl:if test="$rss_ExpandFeed = true()">
                                <xsl:call-template name="RDFMainTemplate.description">
                                    <xsl:with-param name="DescriptionStyle" select="string('display:block;')"/>
                                    <xsl:with-param name="CurrentElement" select="$CurrentElement"/>
                                </xsl:call-template>
                        </xsl:if>
                        <xsl:if test="$rss_ExpandFeed = false()">
                                <xsl:call-template name="RDFMainTemplate.description">
                                    <xsl:with-param name="DescriptionStyle" select="string('display:none;')"/>
                                    <xsl:with-param name="CurrentElement" select="$CurrentElement"/>
                                </xsl:call-template>
                        </xsl:if>
                    </div>
		</xsl:if>
            </xsl:for-each>
        </xsl:template>

	<xsl:template name="RDFMainTemplate.description" 
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
            <xsl:param name="DescriptionStyle"/>
            <xsl:param name="CurrentElement"/>
	    <div id="{$CurrentElement}" class="description" align="$rss_alignValue" style="{$DescriptionStyle} text-
align:{$rss_alignValue};">
		    <xsl:value-of select="ddwrt:FormatDate(dc:date,number($rss_LCID),3)"/>
                <xsl:if test="string-length(rss1:description) &gt; 0">
                    <xsl:variable name="SafeHtml">
                        <xsl:call-template name="GetSafeHtml">
                            <xsl:with-param name="Html" select="rss1:description"/>
                        </xsl:call-template>
                    </xsl:variable>
                     - <xsl:value-of select="$SafeHtml" disable-output-escaping="yes"/>
                </xsl:if>
		    <div class="description">
		        <a href="{ddwrt:EnsureAllowedProtocol(string(rss1:link))}">More...</a>
	        </div>
        </div>
        </xsl:template>


        <xsl:template name="ATOMMainTemplate" 
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
            <xsl:variable name="Rows" select="atom:entry"/>
            <xsl:variable name="RowCount" select="count($Rows)"/>
            <div class="slm-layout-main" >
            <div class="groupheader item medium">
                <a href="{ddwrt:EnsureAllowedProtocol(string(atom:link/@href))}">
                    <xsl:value-of select="atom:title"/>
                </a>
            </div>            
            <xsl:call-template name="ATOMMainTemplate.body">
                <xsl:with-param name="Rows" select="$Rows"/>
                <xsl:with-param name="RowCount" select="count($Rows)"/>
            </xsl:call-template>
            </div>
        </xsl:template>

        <xsl:template name="ATOMMainTemplate.body" 
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
            <xsl:param name="Rows"/>
            <xsl:param name="RowCount"/>
            <xsl:for-each select="$Rows">
                <xsl:variable name="CurPosition" select="position()" />
                <xsl:variable name="RssFeedLink" select="$rss_WebPartID" />
                <xsl:variable name="CurrentElement" select="concat($RssFeedLink,$CurPosition)" />
                <xsl:if test="($CurPosition &lt;= $rss_FeedLimit)">
                            <div class="item link-item" >
                                <a 
href="{concat(&quot;javascript:ToggleItemDescription('&quot;,$CurrentElement,&quot;')&quot;)}" >
                                    <xsl:value-of select="atom:title"/>
                                </a>
                            <xsl:if test="$rss_ExpandFeed = true()">
                                <xsl:call-template name="ATOMMainTemplate.description">
                                    <xsl:with-param name="DescriptionStyle" select="string('display:block;')"/>
                                    <xsl:with-param name="CurrentElement" select="$CurrentElement"/>
                                </xsl:call-template>
                            </xsl:if>
                            <xsl:if test="$rss_ExpandFeed = false()">
                                <xsl:call-template name="ATOMMainTemplate.description">
                                    <xsl:with-param name="DescriptionStyle" select="string('display:none;')"/>
                                    <xsl:with-param name="CurrentElement" select="$CurrentElement"/>
                                </xsl:call-template>
                            </xsl:if>
                            </div>
		</xsl:if>
            </xsl:for-each>
        </xsl:template>

	<xsl:template name="ATOMMainTemplate.description" 
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
            <xsl:param name="DescriptionStyle"/>
            <xsl:param name="CurrentElement"/>
	    <div id="{$CurrentElement}" class="description" align="$rss_alignValue" style="{$DescriptionStyle} text-
align:{$rss_alignValue};">
		<xsl:value-of select="ddwrt:FormatDate(atom:updated,number($rss_LCID),3)"/>
                <xsl:choose>
                    <xsl:when test="string-length(atom:summary) &gt; 0">
                        <xsl:variable name="SafeHtml">
                            <xsl:call-template name="GetSafeHtml">
                                <xsl:with-param name="Html" select="atom:summary"/>
                            </xsl:call-template>
                        </xsl:variable>
                         - <xsl:value-of select="$SafeHtml" disable-output-escaping="yes"/>
                    </xsl:when>
                    <xsl:when test="string-length(atom:content) &gt; 0">
                        <xsl:variable name="SafeHtml">
                            <xsl:call-template name="GetSafeHtml">
                                <xsl:with-param name="Html" select="atom:content"/>
                            </xsl:call-template>
                        </xsl:variable>
                         - <xsl:value-of select="$SafeHtml" disable-output-escaping="yes"/>
                    </xsl:when>
                </xsl:choose>
		    <div class="description">
		        <a href="{ddwrt:EnsureAllowedProtocol(string(atom:link/@href))}">More...</a>
	        </div>
        </div>
        </xsl:template>

        <xsl:template name="ATOM2MainTemplate" 
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
            <xsl:variable name="Rows" select="atom2:entry"/>
            <xsl:variable name="RowCount" select="count($Rows)"/>
            <div class="slm-layout-main" >
            <div class="groupheader item medium">                
                <a href="{ddwrt:EnsureAllowedProtocol(string(atom2:link/@href))}">
                    <xsl:value-of select="atom2:title"/>
                </a>
            </div>
            <xsl:call-template name="ATOM2MainTemplate.body">
                <xsl:with-param name="Rows" select="$Rows"/>
                <xsl:with-param name="RowCount" select="count($Rows)"/>
            </xsl:call-template>
            </div>
        </xsl:template>

        <xsl:template name="ATOM2MainTemplate.body" 
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
            <xsl:param name="Rows"/>
            <xsl:param name="RowCount"/>
            <xsl:for-each select="$Rows">
                <xsl:variable name="CurPosition" select="position()" />
                <xsl:variable name="RssFeedLink" select="$rss_WebPartID" />
                <xsl:variable name="CurrentElement" select="concat($RssFeedLink,$CurPosition)" />
                <xsl:if test="($CurPosition &lt;= $rss_FeedLimit)">
                     <div class="item link-item" >
                                <a 
href="{concat(&quot;javascript:ToggleItemDescription('&quot;,$CurrentElement,&quot;')&quot;)}" >
                                    <xsl:value-of select="atom2:title"/>
                                </a>
                            <xsl:if test="$rss_ExpandFeed = true()">
                                <xsl:call-template name="ATOM2MainTemplate.description">
                                    <xsl:with-param name="DescriptionStyle" select="string('display:block;')"/>
                                    <xsl:with-param name="CurrentElement" select="$CurrentElement"/>
                                </xsl:call-template>
                            </xsl:if>
                            <xsl:if test="$rss_ExpandFeed = false()">
                                <xsl:call-template name="ATOM2MainTemplate.description">
                                    <xsl:with-param name="DescriptionStyle" select="string('display:none;')"/>
                                    <xsl:with-param name="CurrentElement" select="$CurrentElement"/>
                                </xsl:call-template>
                            </xsl:if>
                    </div>
		</xsl:if>
            </xsl:for-each>
        </xsl:template>

	<xsl:template name="ATOM2MainTemplate.description" 
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
            <xsl:param name="DescriptionStyle"/>
            <xsl:param name="CurrentElement"/>
	    <div id="{$CurrentElement}" class="description" align="$rss_alignValue" style="{$DescriptionStyle} text-
align:{$rss_alignValue};">
		    <xsl:value-of select="ddwrt:FormatDate(atom2:updated,number($rss_LCID),3)"/>
                <xsl:choose>
                    <xsl:when test="string-length(atom2:summary) &gt; 0">
                        <xsl:variable name="SafeHtml">
                            <xsl:call-template name="GetSafeHtml">
                                <xsl:with-param name="Html" select="atom2:summary"/>
                            </xsl:call-template>
                        </xsl:variable>
                         - <xsl:value-of select="$SafeHtml" disable-output-escaping="yes"/>
                    </xsl:when>
                    <xsl:when test="string-length(atom2:content) &gt; 0">
                        <xsl:variable name="SafeHtml">
                            <xsl:call-template name="GetSafeHtml">
                                <xsl:with-param name="Html" select="atom2:content"/>
                            </xsl:call-template>
                        </xsl:variable>
                         - <xsl:value-of select="$SafeHtml" disable-output-escaping="yes"/>
                    </xsl:when>
                </xsl:choose>
		    <div class="description">
    		    <a href="{ddwrt:EnsureAllowedProtocol(string(atom2:link/@href))}">More...</a>
	        </div>
        </div>
        </xsl:template>

        <xsl:template name="GetSafeHtml">
            <xsl:param name="Html"/>
            <xsl:choose>
                <xsl:when test="$rss_IsDesignMode = 'True'">
                     <xsl:value-of select="$Html"/>
                </xsl:when>
                <xsl:otherwise>
                     <xsl:value-of select="rssaggwrt:MakeSafe(substring($Html,1,100))"/>
                       --- this is what i change
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>

</xsl:stylesheet>
Random Solutions  
 
programming4us programming4us