DataViewWebpart in matrix display with XSLT modifications

Starting point:

  • SharePoint document library with documents
  • Documents use Category: Global, Regional and Local
  • Each document use a title. Needed for grouping.
  • Calculated-Column to generate a sorting order

Objective point:

  • Documents should be arrange in a matrix.
  • Header column displays the category
  • One document with the same title will and different categories should be display in one row.

Solution:

  • Using SharePoint Designer
  • Adding new DataView WebPart
  • Modify the XSLT

<xsl:template name=”dvt_1″>
<xsl:variable name=”dvt_StyleName”>2ColFrm</xsl:variable>
<xsl:variable name=”Rows” select=”/dsQueryResponse/Rows/Row” />

<xsl:variable name=”dvt_RowCount” select=”count($Rows)” />
<xsl:variable name=”dvt_IsEmpty” select=”$dvt_RowCount = 0″ />
<xsl:choose>
<xsl:when test=”$dvt_IsEmpty”>
<xsl:call-template name=”dvt_1.empty” />
</xsl:when>
<xsl:otherwise>
<table width=”100%” border=”1px” cellpadding=”0″ cellspacing=”0″>
<tr>
<th style=”padding: 4px;”>Product name</th>
<th style=”padding: 4px;”>Global</th>
<th style=”padding: 4px;”>Regional</th>
<th style=”padding: 4px;”>Local</th>
</tr>

<xsl:call-template name=”dvt_1.body”>
<xsl:with-param name=”Rows” select=”$Rows” />
</xsl:call-template>

</table>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name=”dvt_1.body”>
<xsl:param name=”Rows” />
<xsl:for-each select=”$Rows[@txtIWCOrder != ”]”>
<xsl:sort select=”@txtIWCOrder” />
<xsl:call-template name=”dvt_1.rowview” />
</xsl:for-each>

</xsl:template>

<xsl:template name=”dvt_1.rowview”>
<xsl:variable name=”pos” select=”position()”/>
<!–<xsl:variable name=”previewItemID”><xsl:value-of select=”substring-after(preceding-sibling::*[1]/@txtIWCOrder, ‘#’)”/></xsl:variable>–>
<xsl:variable name=”previewItemName”><xsl:value-of select=”substring-before(preceding-sibling::*[1]/@txtIWCOrder, ‘#’)”/></xsl:variable>
<xsl:variable name=”nextItemName”><xsl:value-of select=”substring-before(following-sibling::*[1]/@txtIWCOrder, ‘#’)”/></xsl:variable>
<!–<xsl:variable name=”nextItemID”><xsl:value-of select=”substring-after(following-sibling::*[1]/@txtIWCOrder, ‘#’)”/></xsl:variable>–>
<xsl:variable name=”currentItemID”><xsl:value-of select=”substring-after(@txtIWCOrder,’#’)”/></xsl:variable>
<xsl:variable name=”currentItemName”><xsl:value-of select=”substring-before(@txtIWCOrder,’#’)”/></xsl:variable>

<xsl:choose>
<xsl:when test=”position()=1″>
<xsl:text disable-output-escaping=”yes”>&lt;tr class=”Beginn”&gt;</xsl:text>
<td style=”padding:4px;”>
<xsl:value-of select=”@Title” disable-output-escaping=”yes”/>
</td>

<xsl:choose>
<xsl:when test=”$currentItemID = 1″>
<td  align=”center”><a href=”{@FileDirRef}/{@FileLeafRef}” title=”{@Title} – {@Category}”>X</a></td>
<xsl:if test=”$nextItemName !=$currentItemName”><td  align=”center”>-</td></xsl:if>
<xsl:if test=”$nextItemName !=$currentItemName”><td  align=”center”>-</td></xsl:if>
</xsl:when>
<xsl:when test=”$currentItemID = 2″>
<td  align=”center”>-</td>
<td  align=”center”><a href=”{@FileDirRef}/{@FileLeafRef}” title=”{@Title} – {@Category}”>X</a></td>
<xsl:if test=”$nextItemName !=$currentItemName”><td  align=”center”>-</td></xsl:if>
</xsl:when>
<xsl:when test=”$currentItemID = 3″>
<td  align=”center”>-</td>
<td  align=”center”>-</td>
<td  align=”center”><a href=”{@FileDirRef}/{@FileLeafRef}” title=”{@Title} – {@Category}”>X</a></td>
</xsl:when>
</xsl:choose>

</xsl:when>
<xsl:when test=”$currentItemName = $nextItemName”>
<!– n-node –>
<xsl:text disable-output-escaping=”yes”>&lt;tr class=”Equal”&gt;</xsl:text>
<td class=”Equal” style=”padding:4px;”>
<xsl:value-of select=”@Title” disable-output-escaping=”yes”/>
</td>
<td class=”multiple-CurNext”  align=”center”><a href=”{@FileDirRef}/{@FileLeafRef}” title=”{@Title} – {@Category}”>X</a></td>

</xsl:when>
<xsl:when test=”$currentItemName != $nextItemName”>
<xsl:if test=”$currentItemName != $previewItemName”>
<xsl:text disable-output-escaping=”yes”>&lt;tr class=”Single”&gt;</xsl:text>
<td style=”padding:4px;”>
<xsl:value-of select=”@Title” disable-output-escaping=”yes”/>
</td>

<xsl:choose>
<xsl:when test=”$currentItemID = 1″>
<td  align=”center”><a href=”{@FileDirRef}/{@FileLeafRef}” title=”{@Title} – {@Category}”>X</a></td>
<xsl:if test=”$nextItemName !=$currentItemName”><td  align=”center”>-</td></xsl:if>
<xsl:if test=”$nextItemName !=$currentItemName”><td  align=”center”>-</td></xsl:if>
</xsl:when>
<xsl:when test=”$currentItemID = 2″>
<td  align=”center”>-</td>
<td  align=”center”><a href=”{@FileDirRef}/{@FileLeafRef}” title=”{@Title} – {@Category}”>X</a></td>
<xsl:if test=”$nextItemName !=$currentItemName”><td  align=”center”>-</td></xsl:if>
</xsl:when>
<xsl:when test=”$currentItemID = 3″>
<td  align=”center”>-</td>
<td  align=”center”>-</td>
<td  align=”center”><a href=”{@FileDirRef}/{@FileLeafRef}” title=”{@Title} – {@Category}”>X</a></td>
</xsl:when>
</xsl:choose>

<xsl:text disable-output-escaping=”yes”>&lt;/tr&gt;</xsl:text>
</xsl:if>

<xsl:if test=”$currentItemName = $previewItemName”>
<!– Only table section headline –>
<xsl:if test=”$currentItemName = $nextItemName”>
<xsl:text disable-output-escaping=”yes”>&lt;tr class=”Multiple”&gt;</xsl:text>
<td style=”padding:4px;”> <xsl:value-of select=”@Title” disable-output-escaping=”yes”/>
</td>
</xsl:if>
<td  class=”multiple” align=”center” ><a href=”{@FileDirRef}/{@FileLeafRef}” title=”{@Title} – {@Category}”>X</a></td>

<xsl:if test=”$currentItemName != $nextItemName”>
<td  class=”multiple-empty” align=”center”>-</td>
</xsl:if>
</xsl:if>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
<xsl:if test=”position() = last()”>
<xsl:text disable-output-escaping=”yes”>&lt;/tr&gt;</xsl:text>
</xsl:if>
</xsl:template>

Leave a Reply

Your email address will not be published. Required fields are marked *