I have a list of contacts in SharePoint 2010 that I want to display in 3 different tables based on a TablePos
attribute using a custom stylesheet. The TablePos
attribute can have a value of Left
, Center
, or Right
. When I don't use the <xsl:if>
element, the list view displays all the items in the list view web part. However, when I use the <xsl:if>
element to limit the items returned to only those with TablePos='Left'
, the list view won't render at all. SharePoint doesn't throw an error, it just doesn't render any HTML.
When I use an online XSL Transformation tool, it outputs the html correctly to only show those items that have TablePos='Left'
like below, but when I attach the XSL stylesheet to a list view web part, it won't render anything:
<div>
<div id="tablePos1">
<table class="it-contacts">
<tr>
<td><img src="/test-site/ITMockup/PublishingImages/staff/doe.jpg" alt="John Doe"></td>
<td>John Doe
<br>Chief Information Officer, IT Program Director
<br>555-7337
<br><a href="mailto:[email protected]">[email protected]</a></td>
</tr>
</table>
</div>
</div>
Here's the pertinent XML:
<dsQueryResponse ViewStyleID="" BaseViewID="1" TemplateType="100" RowLimit="30">
<Rows>
<Row ID="1" Title="John Doe" Position="Chief Information Officer, IT Program Director" Duties="Lead IT programs." Phone="555-7337" Email="<a href="mailto:[email protected]">[email protected]</a>" Photo="/test-site/ITMockup/PublishingImages/staff/doe.jpg" TablePos="Left" />
<Row ID="2" Title="Bobby Sue" Position="Deputy CIO" Duties="Provides overall direction and management for the GIS and Application Development Units" Phone="555-7331" Email="<a href="mailto:[email protected]">[email protected]</a>" Photo="/test-site/ITMockup/PublishingImages/staff/sue.jpg" TablePos="Center" />
<Row ID="3" Title="Sally Lu" Position="Administrative Resources Manager" Duties="Manages the Word Processing staff" Phone="555-7288" Email="<a href="mailto:[email protected]">[email protected]</a>" Photo="/test-site/ITMockup/PublishingImages/staff/lu.jpg" TablePos="Right" />
</Rows>
</dsQueryResponse>
And here's the corresponding XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<div>
<div id="tablePos1">
<table class="it-contacts">
<xsl:apply-templates/>
</table>
</div>
</div>
</xsl:template>
<xsl:template match="/dsQueryResponse/Rows/Row">
<xsl:if test="@TablePos = 'Left'">
<tr>
<td>
<img>
<xsl:attribute name="src">
<xsl:value-of select="@Photo" />
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="@Title" />
</xsl:attribute>
</img>
</td>
<td>
<xsl:value-of select="@Title" />
<br/>
<xsl:value-of select="@Position" />
<br/>
<xsl:value-of select="@Phone" />
<br/>
<xsl:value-of select="@Email" disable-output-escaping="yes" />
</td>
</tr>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Any ideas why this isn't rendering in the list view web part?