Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm starting to work with custom view stylesheets on an external list. I am finding the header is rendering twice - once upon initial page render and again after the data is returned from the server:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:output method="html" indent="no"/>
  <xsl:param name="XmlDefinition" select="."/>
  <xsl:template match="/">
    <table>
      <tr>
        <xsl:for-each select="$XmlDefinition/ViewFields/FieldRef">
          <th>
            <xsl:value-of select="@DisplayName"/>
          </th>
        </xsl:for-each>
      </tr>
      <xsl:for-each select="/dsQueryResponse/Rows/Row">
        <xsl:variable name="row" select="." />
        <tr>
          <xsl:for-each select="$XmlDefinition/ViewFields/FieldRef">
            <xsl:variable name="fieldName" select="@Name" />
            <td>
              <xsl:value-of select="$row/@*[name() = $fieldName]" disable-output-escaping="yes"/>
            </td>
          </xsl:for-each>
        </tr>
      </xsl:for-each>
    </table>
  </xsl:template>
</xsl:stylesheet>

When I look at the resulting HTML I see two table elements created, one with just the header and one with the header and data. Any thoughts on how to prevent SharePoint from rendering the header until the data is available?

share|improve this question
add comment

1 Answer

Figured out how to workaround it using an XSLT if statement:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:output method="html" indent="no" />
  <xsl:param name="XmlDefinition" select="." />
  <xsl:template match="/">
    <xsl:if test="count(/dsQueryResponse/Rows/Row) &gt; 0">
      <table border="0" cellspacing="0">
        <tbody>
          <xsl:for-each select="/dsQueryResponse/Rows/Row">
            <xsl:variable name="row" select="." />
            <tr>
              <xsl:for-each select="$XmlDefinition/ViewFields/FieldRef">
                <xsl:variable name="fieldName" select="@Name" />
                <xsl:apply-templates select=".">
                  <xsl:with-param name="thisNode" select="$row"/>
                </xsl:apply-templates>
              </xsl:for-each>
            </tr>
          </xsl:for-each>
        </tbody>
      </table>
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tbody>
          <tr>
            <td colspan="2" class="ms-partline">
              <img src="/_layouts/images/blank.gif" width="1" height="1" alt="" />
            </td>
          </tr>
          <tr>
            <td class="ms-addnew" style="padding-bottom: 3px">
              <span style="height:10px;width:10px;position:relative;display:inline-block;overflow:hidden;" class="s4-clust">
                <img src="/_layouts/images/fgimg.png" alt="" style="left:-0px !important;top:-128px !important;position:absolute;" />
              </span>
              <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
              <a class="ms-addnew" href="/_Layouts/ScSignup.aspx">Create a Workspace</a>
            </td>
          </tr>
          <tr>
            <td>
              <img src="/_layouts/images/blank.gif" width="1" height="5" alt="" />
            </td>
          </tr>
        </tbody>
      </table>
    </xsl:if>
  </xsl:template>
  <xsl:template match="FieldRef[@Name='Url' and @Format='Hyperlink']" priority="1">
    <xsl:param name="thisNode" select="."/>
    <xsl:variable name="url" select="normalize-space(substring-before($thisNode/@*[name()=current()/@Name],','))" />
    <xsl:variable name="desc" select="normalize-space(substring-after($thisNode/@*[name()=current()/@Name],','))" />
    <xsl:variable name="descfld" select="$thisNode/@Description"/>
    <xsl:variable name="urlfld" select="$thisNode/@Url"/>
    <td style="padding-bottom: 5px" class="ms-vb">
      <img src="/_layouts/images/square.gif" alt="" />
      <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
    </td>
    <td>
      <a href="{$url}" alt="{$desc}">
        <xsl:value-of select="$desc"/>
      </a>
    </td>
  </xsl:template>
</xsl:stylesheet>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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