Using xsl stylesheet with List View Web Part to display custom text
-
01-10-2020 - |
Вопрос
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>
Решение
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>
Не связан с sharepoint.stackexchange