Print

SHAREPOINTERS: A Brief XSL Primer with the XML Web Part



Email
April 29, 2009 —  (Page 1 of 2)
I recently posted some code to my blog that shows people how to display a styled version of their Twitter RSS feed on any SharePoint page using the XML Web Part and XSL. To see screenshots of the web part in action visit the original blog post. While the code is quite simple, many SharePoint professionals are new to XSL, so I thought this might be a good time to give a really quick introduction.

First, what is XSL, and why is it important to SharePoint? XSL stands for Extensible Stylesheet Language and it is primarily used to transform raw XML into various human readable formats (most commonly HTML). To parse an XML file, XSL uses a technology known as XPath (XML Path Language). XPath uses expressions to select sets of nodes in an XML file and hand them off in a useful manner to XSL for styling as HTML. Many of the out-of-the-box SharePoint Web parts utilize XML and XSL to allow developers and designers to style data easily.

For displaying the Twitter feed I utilized the XML Web Part, which is a very simple Web part that just connects an XML file (local or on a remote server) with an XSL stylesheet. In this case, the XML file was an RSS feed of my Twitter timeline. RSS is nothing more than XML in a specific format. SharePoint will load this XML data and apply the assigned XSL. To understand the XSL, let’s look at some of the key lines from my example.

The XSL stylesheet starts with:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet
     version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output method="html" />

This defines the encoding of the stylesheet to allow for non-English characters and defines which version of XSL will be implemented. At the end the output method is set to HTML (XSL could be used to create displays in other languages as well). The next line is:

<xsl:template match="rss/channel">

The <xsl:template> uses XPath to find a node set in the XML data, in this case it will look first for a node called “rss” and then for one called “channel” under it. Once it finds that node, it will perform the defined transformations inside the template. This begins by declaring several standard CSS styles much like you would in a typical HTML file. These classes will be used in the coming transformations. After the style declaration is this line:




Pages 1 2 


Share this link: http://sdt.bz/33438
 
Most Read  Latest News  Resources

close
NEXT ARTICLE
Book Excerpt: The Tangled Web: A Guide to Securing Modern Web Applications
From Part III: A Glimpse of Things to Come Read More...
 
 
 




News on Monday  more>>
Android Developer News  more>>
SharePoint Tech Report  more>>
Big Data TechReport  more>>

   
 
 

 


Download Current Issue
MAY 2013 PDF ISSUE

Need Back Issues?
DOWNLOAD HERE

Want to subscribe?