SharePoint Marketing Suite Dedicated SharePoint 2013
SharePoint Websites: What's Popular | Most Rated | Latest | Surprise Me!

Apply a Style to the XML Viewer Web Part

Author: Luis Kerr 12,021 views

Apply a Style to the XML ViewerXML Viewer web part for SharePoint 2010 (Called XML Web Part under SharePoint 2007) is a very useful to display structured data and XML-based documents. The good thing about this XML web part is that it allows you to customize your XML document with the help of XSLT (Extensible Stylesheet Language Transformations) by applying the style to the XML before the content is displayed. There are many ways of using the XML Viewer web part, but for now I will concentrate on displaying a RSS feed. And what better feed I could come up with than the TopSharePoint.com Blog feed.

So, let’s start with adding the web part to the page. Click on Site Action and then select Edit Page.
Apply a Style to the XML - Step 1
Pick a side where the new XML Viewer will be displayed on the page. For this example I used the right panel. Click on the “Add a Web Part” link and then under the top ribbon make sure you’re under Browse tab.
Apply a Style to the XML - Step 2
Select Content Rollup and then XML Viewer and click on the Add button.
Apply a Style to the XML - Step 3
Under the newly added web part click on the “open the tool pane” link to customize it.
Apply a Style to the XML - Step 4
On the XML Viewer web part settings panel, under XML Link plug in your RSS feed and then click on XSL Editor button to get to the Text Editor webpage dialog window.
Apply a Style to the XML - Step 5
Apply a Style to the XML - Step 6
Copy & Paste the code below and then click OK.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:param name="TITLE"/>
<xsl:template match="rss">
  <div style="background:#fff; padding:0; font-size:10px;">
      <xsl:for-each select="channel/item">
        <a href="{link}" target="_new"><xsl:value-of select="title"/></a><br/>    
        <xsl:value-of disable-output-escaping="yes" select="description"/><br/>
      </xsl:for-each>
  </div>
</xsl:template>
<xsl:template match="description"><xsl:value-of select="."/><br/></xsl:template>
</xsl:stylesheet>

Make the necessary aesthetics changes: web part Title, Width, Height and Chrome Type and click OK.
Apply a Style to the XML - Step 7
Of course the XSL style sheet provided can be customized farther, like referencing an external CSS by adding a class attribute to the div tag instead of using inline styling. And, here is the outcome:
Apply a Style to the XML - Step 8

 
 
 
 

6 responses so far, want to say something?

  1. Krysti says:

    Thanks so much! Using this on site intranet to display twitter updates. With minor modifications, this is exactly what I’ve been looking for!!

  1. Neil says:

    I have followed the same steps but have this error:

    Cannot retrieve the URL specified in the XML Link property. For more assistance, contact your site administrator.

    Any idea?

  1. Luis Bernal says:

    Muchas gracias un valioso aporte, funciona perfecto.

  1. Eric Stepek says:

    I’m using this technique for my external facing Blog, which is SP2010. I’m just learning xsl, but can you illustrate how to bold the Title and remove the “Body:” caption? I dont mind the Category of published date, but want to remove the BODY and bold the title. My list show as:

    Blog Title <—- Not bold

    BODY: <—– Bold
    blog content

    Category: Category 1
    Published: 12/12/2011 11:19AM

  1. Nada says:

    Eric, for Title it’s all in CSS as per the Body, play with “description”. I would remove the whole line: xsl:value-of disable-output-escaping=”yes” select=”description”

  1. Libin says:

    Nice article , thanks to giving this simple solution. Thanks.

Leave a Reply


eight − = 1

2 319
Featured
SharePoint
Sites

Recent Blog Posts

    Best SharePoint Sites In:

    © 2013 Top SharePoint Sites - All Rights Reserved About Us | Authors | Writers Guidelines | Contact Us | Advertise | Sign Up for Our Newsletter