Displaying the First ‘x’ Words of a Rich Text Column in a Dataview

// June 22nd, 2009 // Uncategorized

Working with datviews and Sharepoint designer often, i come across the need to show the first few words of a rich text column often, especially the “body” tag say of a blog.

It would be pretty easy using the ddwrt:limit function or the substring() for any other column, but in this case the body tag is actually in html format. The “Limit” function then brings us back ugly part html which is no good to display.

Luckily there is a way. There are essentially two steps here:

1. strip the html
2. return the first ‘x’ words

I used a simple template to strip the html, here it is:

 xhtml |  copy code |? 
01
02
  
03
    
04
    
05
     
06
      
07
        
08
      
09
     
10
     
11
      
12
     
13
    
14
 
15

Then we need to return the first ‘x’ words:

 xhtml |  copy code |? 
01
  
02
      
03
      
04
      
05
      
06
        07
                ">  
08
              
09
              
10
                  
11
                  
12
                  
13
              
14
          
15
        16
                    string-length(substring-before($TextData, '  ')) > 0)">  
17
              
18
          
19
          
20
              
21
          
22
      
23

24

Then just under your

 xhtml |  copy code |? 
1
line:

 xhtml |  copy code |? 
1
2
				  
3
      
4
        
5
      
6
   
7

Credit given: Thanks to Mark’s post for the help.

I can like it: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • muti
  • Digg
  • del.icio.us
  • DZone
  • Fark
  • Fleck
  • Furl
  • Technorati

Leave a Reply