Usage

The SPXSLT ZIPped download file contains each individual template wrapped up for individual use. 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 could 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 just to keep your XSL well-organized. 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 central location 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 Server 2010 environment, I'd recommend placing the XSL files in the /Style Library/XSL Style Sheets location, as this is where SharePoint stores its 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>

Last edited Feb 18, 2011 at 3:01 AM by sympmarc, version 11

Comments

No comments yet.