Skip to content

Instantly share code, notes, and snippets.

@joshbooker
Created November 17, 2012 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshbooker/4095951 to your computer and use it in GitHub Desktop.
Save joshbooker/4095951 to your computer and use it in GitHub Desktop.
<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">
<!--
Add Param binding to XLV like so:
<ParameterBinding Name="Organisation" DefaultValue="Technical; Mann Link Business; Directors" />
-->
<!-- import the standard main.xsl, so we have all standard stuff -->
<xsl:import href="/_layouts/xsl/main.xsl"/>
<xsl:output method="html" indent="no"/>
<!-- we get here the Organisation Parameter from the PropertyBinding with the same name -->
<xsl:param name="Organisation" />
<!-- this is the standard XmlDefinition parameter - the XLV initializes this one with the view schema -->
<xsl:param name="XmlDefinition" />
<xsl:variable name="Organisation2" select="Technical"></xsl:variable>
<!-- this variable contains the parsed configuration data like <token>Technical</token><token>Mann Link Business</token> etc -->
<xsl:variable name="tokens">
<xsl:call-template name="Tokenize">
<xsl:with-param name="string" select="$Organisation" />
<xsl:with-param name="delimiter" select="'; '" />
</xsl:call-template>
</xsl:variable>
<!-- here we create a copy of the original XmlDefinition, alter the Query to build <Where><Or><Includes> filter -->
<xsl:variable name="XmlDefinition2Raw">
<xsl:apply-templates mode="transform-schema" select="$XmlDefinition" >
<xsl:with-param name="tokenSet" select="msxsl:node-set($tokens)" />
</xsl:apply-templates>
</xsl:variable>
<!-- the one above is a sequence of tags, in order that it can be used exactly like the standard $XmlDefinition it should be converted to a node set -->
<xsl:variable name="XmlDefinition2" select="msxsl:node-set($XmlDefinition2Raw)" />
<!-- this one is simply a copy of the template with the same match from the standard vwstyles.xsl (thus we override it), the only difference is that it uses our trimmed $XmlDefinition2 instead of the standard $XmlDefinition -->
<xsl:template match="/">
<!-- josh debug - print tokens and altered view query
<xmp><xsl:copy-of select="$tokens" /></xmp>
<xmp><xsl:copy-of select="$XmlDefinition2/View/Query" /></xmp> -->
<xsl:choose>
<xsl:when test="$RenderCTXOnly='True'">
<xsl:call-template name="CTXGeneration"/>
</xsl:when>
<xsl:when test="($ManualRefresh = 'True')">
<xsl:call-template name="AjaxWrapper" />
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates mode="RootTemplate" select="$XmlDefinition2"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- the same as the template above -->
<xsl:template name="AjaxWrapper" ddwrt:ghost="always">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top">
<xsl:apply-templates mode="RootTemplate" select="$XmlDefinition2"/>
</td>
<td width="1%" class="ms-vb" valign="top">
<xsl:variable name="onclick">
javascript: <xsl:call-template name="GenFireServerEvent">
<xsl:with-param name="param" select="'cancel'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="alt">
<xsl:value-of select="$Rows/@resource.wss.ManualRefreshText"/>
</xsl:variable>
<a href="javascript:" onclick="{$onclick};return false;">
<img src="/_layouts/images/staticrefresh.gif" id="ManualRefresh" border="0" alt="{$alt}"/>
</a>
</td>
</tr>
</table>
</xsl:template>
<!-- this template creates the copy of the standard $XmlDefinition trimming the Query and replacing with <Or><Includes> -->
<xsl:template mode="transform-schema" match="View" >
<xsl:param name="tokenSet" />
<!-- copy the root View element -->
<xsl:copy>
<!-- copy the root View element's attributes -->
<xsl:copy-of select="@*"/>
<!-- copy the child elements of the root View element -->
<xsl:for-each select="child::*">
<xsl:choose>
<xsl:when test="name() = 'Query'">
<!-- special handling of the Query element -->
<Query><Where><Or>
<xsl:for-each select="$tokenSet/token">
<Includes>
<FieldRef Name="TG_Organization"/>
<Value Type="Lookup"><xsl:copy-of select="text()"/></Value>
</Includes>
<!-- wip - apply the includes template - wip
<xsl:call-template name="Includes">
<xsl:with-param name="FieldRef" select="" />
<xsl:with-param name="Value" select="" />
</xsl:call-template>-->
</xsl:for-each>
</Or></Where></Query>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template name="Includes">
<Includes>
<FieldRef Name="TG_Organization"/>
<Value Type="Lookup">{Org1}</Value>
</Includes>
</xsl:template>
<!-- several helper templates that parse the parameter string and return the value from key; value pairs-->
<!-- returns value of token after key token - not in use -->
<!-- expects token set like <token>Key</token><token>Value</token><token>Key</token><token>Value</token>...Etc -->
<!-- as from parameter like "Key;Value;Key;Value;"...Etc w delim ';' -->
<xsl:template name="GetValueFromKey">
<xsl:param name="tokenSet" />
<xsl:param name="key" />
<xsl:apply-templates select="$tokenSet/token[text() = $key]" />
</xsl:template>
<xsl:template name="NextNode" match="token">
<xsl:value-of select="following-sibling::*"/>
</xsl:template>
<!-- this splits string by delim and returns token set -->
<!--like <token>Val1</token><token>Val2</token><token>Valn</token>...etc. -->
<xsl:template name="Tokenize">
<xsl:param name="string" />
<xsl:param name="delimiter" select="' '" />
<xsl:choose>
<xsl:when test="$delimiter and contains($string, $delimiter)">
<token>
<xsl:value-of select="substring-before($string, $delimiter)" />
</token>
<xsl:call-template name="Tokenize">
<xsl:with-param name="string" select="substring-after($string, $delimiter)" />
<xsl:with-param name="delimiter" select="$delimiter" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<token>
<xsl:value-of select="$string" />
</token>
<!-- <xsl:text> </xsl:text> -->
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
@joshbooker
Copy link
Author

Add Parameter Binding to XLV like so:

@joshbooker
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment