Skip to content

Instantly share code, notes, and snippets.

@emiliano-poggi
Last active August 29, 2015 14:15
Show Gist options
  • Save emiliano-poggi/5750df37a75a37368328 to your computer and use it in GitHub Desktop.
Save emiliano-poggi/5750df37a75a37368328 to your computer and use it in GitHub Desktop.
SharePoint 2013 How To XSL Link Option List View Web Part

SharePoint 2013 How To XSL Link Option List View Web Part

XSL Link option allows to link an XSLT stylesheet uploaded to the site for processing and transforming List View data to which the web part is connetcted.

The input xml passed to XSLT is described here https://msdn.microsoft.com/en-us/library/office/ff602042(v=office.14).aspx

There are two main ways to work:

  • Just transform input data and render it as wanted
  • Include the default templates and override those as required

When overriding tempaltes:

  • To override the template for the headers, use header mode.
  • To override the template for the body, use body mode.
  • Consider having a look to _layouts (sharepoint server hive folder) main.xsl and internal.xsl to check the templates to override.
<!--
Just apply default stylesheet (render data as without additional XSLT):
-->
<?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" indent="no"/>
<xsl:include href="/_layouts/xsl/main.xsl"/>
<xsl:include href="/_layouts/xsl/internal.xsl"/>
</xsl:stylesheet>
<!-- Render data as by default, but without the header information of the list -->
<?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" indent="no"/>
<xsl:include href="/_layouts/xsl/main.xsl"/>
<xsl:include href="/_layouts/xsl/internal.xsl"/>
<xsl:template match="FieldRef" mode="header">
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>
<!-- Print input data to the web page, jsut to view field names and other useful input information -->
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ddwrt2="urn:frontpage:internal">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:ghost="">
<xmp><xsl:copy-of select="*"/></xmp>
<xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:whitespace-preserve="yes" xml:space="preserve">
<!-- example taken from http://www.glynblogs.com/2011/04/overriding-the-presentation-of-an-xslt-list-view-web-part.html -->
<xsl:template name="FieldRef_body.Status" match="FieldRef[@Name='Status']" mode="body">
<xsl:param name="thisNode" select="."/>
<xsl:choose>
<xsl:when test="$thisNode/@*[name()=current()/@Name] = 'Completed'">
<img src="/_layouts/images/IMNON.png" alt="Status: {$thisNode/@Status}"/>
</xsl:when>
<xsl:when test="$thisNode/@*[name()=current()/@Name] = 'In Progress'">
<img src="/_layouts/images/IMNIDLE.png" alt="Status: {$thisNode/@Status}"/>
</xsl:when>
<xsl:otherwise>
<img src="/_layouts/images/IMNBUSY.png" alt="Status: {$thisNode/@Status}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment