SPXSLT (SharePoint XSL Templates) Release 0.0.1
The SPXSLT Codeplex Project has been languishing a bit due to a lack of time to focus on it on my part. (See my earlier blog post New CodePlex Project: SharePoint XSL Templates (SPXSLT) for more information on what this project is about.) These XSL templates can be used in your Data View Web Parts (DVWPs), Content Query Web Parts (CQWPs), and any other Web Parts you may have which rely on XSL transformations to display data.
Tonight I’ve packaged up the first real downloadable release, v0.0.1. The SPXSLT ZIPped download file contains each individual template wrapped up for individual use.
The main impetus for the change was a little Twitter conversation I had with Matt Hawley over at Codeplex in which he let me know that technically the project wasn’t “legal” for Codeplex because it didn’t have any code downloads available. I had the code embedded in the documentation rather than available for download.)
The project is gathering momentum and can benefit greatly from your contributions. Submit your useful XSL templates by posting them to the Discussions (if it’s a new template or template idea) or the Issue Tracker (if there’s a problem with an existing template) or contact me directly via the Codeplex site.
If you’ve submitted a template and don’t see it in the releases yet, I apologize for any delay. While I want to post any and all useful templates, I also want to validate each one, and that requires time (a precious commodity!). Please be patient, and don’t hesitate to ping me if you think I’ve forgotten about your submission.
Usage
To use a template within your own Data View Web Parts (DVWPs), Content Query Web Parts (CQWPs), etc., you only need each template itself. For example, if you wanted to use the ToUpper template, you would simply add the XSL below into your DVWP’s XSL section:
<xsl:template name="ToUpper"> <xsl:param name="StringValue"/> <xsl:value-of select="translate($StringValue, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/> </xsl:template>
Generally, you’ll want to add the templates to the bottom of the XSL section. In a simple DVWP, this would mean below the dvt_1.rowview template.
If you’d like to centralize your XSL template for greater reuse (highly recommended), you can put the individual XSL files into a Document Library for storage. In a WSS or SharePoint Foundation environment, I’d recommend using a Document Library in the root site of your Site Collection. In a MOSS or SharePoint 2010 environment, I’d recommend placing the XSL files in the /Style Library/XSL Style Sheets location, as this is where SharePoint stores it’s XSL by default.
If you want to use more than one of these templates on a regular basis, you should combine them into fewer files, or even one file. Only you will be able to determine what is the most efficient configuration, as it will be a balancing act between the number of files and the number of templates you use on a regular basis. I often will put all of the templates I use frequently into a single file called Utilities.XSL.
As I mentioned above, each of the XSL files are packaged for individual use. If you’d like to use the ToUpper template and have stored it in /Style Library/XSL Style Sheets, then you can include it in your DVWP with the xsl:import tag:
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal"> <xsl:import href="/Style Library/XSL Style Sheets/ToUpper.xsl"/> <xsl:output method="html" indent="no"/>
Note that the xsl:import tag must be in exactly this location at the top of your XSL section to work. Also, the namespace definitions which are included as part of the xsl:stylesheet tag are required and should not be changed.
In each individual XSL file, the template has the required wrapper for the xsl:import approach to work:
<?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal"> <xsl:output method="html" indent="no"/> <xsl:template name="ToUpper"> <xsl:param name="StringValue"/> <xsl:value-of select="translate($StringValue, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/> </xsl:template> </xsl:stylesheet>
If you combine templates into a single file, there should only be a single wrapper for all of the templates in the file, like this:
<?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal"> <xsl:output method="html" indent="no"/> <xsl:template name="ToUpper"> <xsl:param name="StringValue"/> <xsl:value-of select="translate($StringValue, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/> </xsl:template> <xsl:template name="ToLower"> <xsl:param name="StringValue"/> <xsl:value-of select="translate($StringValue, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/> </xsl:template> </xsl:stylesheet>
Available Templates
Name | Short Description | Dependencies | Type | Categories |
---|---|---|---|---|
ConvertToCelsius | Converts a temperature in degrees Farenheit to degrees Celsius. | NA | Template | Conversion |
FirstNWords | Displays the first N words from a string of text. (Use StripHTML first if your content includes markup.) | NA | Template | String |
GetPercentileValue | Given a nodeset and a percentile (expressed as a number from 0-100), returns the percentile value of a column. | NA | Template | Statistical |
GetUserID | This template returns the user’s ID from a Person or Group value. | NA | Template | User |
GetUserIDs | This template returns the user IDs from a Person or Group column which allows multi-select. | GetUserID | Template | User |
GetUserName | This template returns the user’s name from a Person or Group value. | NA | Template | User |
GetUserEmail | This template returns the user’s Email from a Person or Group value. | NA | Template | User |
MailtoUser | This template returns a mailto: link for the user’s Email from a Person or Group value. | NA | Template | User |
MailtoUsers | This template returns mailto: links for the user Emails from a Person or Group column which allows multi-select. | MailtoUser | Template | User |
MultiSelectDisplay | This template lets you display the values in a multiselect column “nicely”, using a separator of your choosing. | NA | Template | Multi-Select |
MultiSelectValueCheck | This template checks to see if a specific value is present in a multi-value column. | NA | Template | Multi-Select |
StripHTML | Strips the HTML tags out of a section of content. | NA | Template | HTML |
ToLower | Converts a string to lower case. | NA | Template | String |
ToUpper | Converts a string to upper case. | NA | Template | String |
Great, thanks a lot for this, Marc! I’ve been meaning to compare my own striphtml and FirstN Words code with those for a while now, now I’ve got a good reason to do so.
By the way, the links under “Available Templates” do not work, think they should all point to codeplex
Rene:
Thanks for pointing out the bad links; I was too fast with the cut and paste. And you’re welcome!
M.