0

I am using a custom xsl stylesheet in Sharepoint 2013 listview webpart using the "XSL Link" property.

The list view shows some items based on a filter. I want to display custom text such as "No Items" when there are zero items in the list view using the xsl stylesheet.

How do I achieve this? Part of the code of the custom xsl file is included below

<xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema">
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row" />
<table>
<xsl:for-each select="$Rows">
<xsl:call-template name="dvt_1.rowview"></xsl:call-template> 
</xsl:for-each>
</table>
</xsl:template>

<xsl:template name="dvt_1.rowview">

<tr>
<td><img height="78" width="60"><xsl:attribute name="src"><xsl:value-of select="@Photo"/></xsl:attribute></img></td>
<td>
<table style="margin-left:10px;">
<tr><td><xsl:value-of select="@FullName"/></td></tr>
<tr><td><xsl:value-of select="@DOBinWords"/></td></tr>
</table>
</td>
</tr>
</xsl:template>
3
  • Where / how would you like to display this text exactly? In on of the fields (like Title) of the view, or you don't want to see any field headers in this case as well?
    – pholpar
    Commented Feb 2, 2015 at 7:01
  • I dont want to see any headers. Just the text. Like in the table which the xsl creates there should be only one row having the text "No items" or not create a table at all. Just output text as we output in html like using a <span> tag or something Commented Feb 2, 2015 at 9:05
  • Hi @AparnaSarkar if my or any answer has solved your question please consider accepting it by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. Commented Mar 31, 2015 at 13:08

1 Answer 1

0

Hi Aparna,

You can create a condition to test for no rows

count($Rows) = 0

Then put this into a choose block

<xsl:choose>
    <xsl:when test="count($Rows) = 0">
        <span>No items</span>
    </xsl:when>
    <xsl:otherwise>
        <!--Things to do when there are rows -->
    </xsl:otherwise>
</xsl:choose>

You full code for the / template would look like this

<xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema">
    <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row" />
    <xsl:choose>
        <xsl:when test="count($Rows) = 0">
            <span>No items</span>
        </xsl:when>
        <xsl:otherwise>
            <table>
                <xsl:for-each select="$Rows">
                    <xsl:call-template name="dvt_1.rowview"></xsl:call-template> 
                </xsl:for-each>
            </table>                
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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