0

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:john.doe@example.com">john.doe@example.com</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="&lt;a href=&quot;mailto:john.doe@example.com&quot;&gt;john.doe@example.com&lt;/a&gt;" 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="&lt;a href=&quot;mailto:bobby.sue@example.com&quot;&gt;bobby.sue@example.com&lt;/a&gt;" 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="&lt;a href=&quot;mailto:sally.lu@example.com&quot;&gt;sally.lu@example.com&lt;/a&gt;" 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?

  • 2
    Have you considered using a filter on the data source instead of the xls:if? – teylyn Jun 5 '15 at 1:14
  • And you aren't for eaching over the result set – Eric Alexander Jun 5 '15 at 2:59
0

After taking some time away from it, I figured out what was going on. When I initially added the list view web part, the TablePos column had not yet been created in the list, and wasn't included in the view of the web part. I was generating the XML using a second list view web part that included the TablePos column by default, so it was returning XML for that column. When I modified the view of the first web part to include the new TablePos column and added the custom XSLT, the list returned only those items that had TablePos='Left'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.