Question

This is probably simple but here goes. I want to customize the xslt layout of a list view. The idea is to add a header to the top which shows the name of the list. Here is what I have so far.

    <xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" 
                xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" 
                exclude-result-prefixes="xsl msxsl ddwrt" 
                xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" 
                xmlns:asp="http://schemas.microsoft.com/ASPNET/20" 
                xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
                xmlns:SharePoint="Microsoft.SharePoint.WebControls" 
                xmlns:ddwrt2="urn:frontpage:internal" 
                xmlns:o="urn:schemas-microsoft-com:office:office">
  <xsl:include href="/_layouts/xsl/main.xsl"/>
  <xsl:include href="/_layouts/xsl/internal.xsl"/>
  <xsl:template match="/">
    <span class="content-page-top-span">
      <div class="list-header">
        <span>
          <xsl:value-of select="$ListTitle"/>
        </span>
      </div>
      <xsl:apply-templates/>
    </span>
  </xsl:template> 
</xsl:stylesheet>

My issue is that the while the header shows up all nice as expected the actual list columns/data are missing. What did I do wrong? Any help much appreciated from an XSLT newbie.

Était-ce utile?

La solution

Original root template for XsltListViewWebPart comes from 14/TEMPLATE/LAYOUTS/XSL/vwstyles.xsl file. The code is as follows:

<xsl:template match="/">
  <xsl:choose>
    <xsl:when test="$RenderCTXOnly='True'">
      <xsl:call-template name="CTXGeneration"/>
    </xsl:when>
    <xsl:when test="($ManualRefresh = 'True')">
      <xsl:call-template name="AjaxWrapper" />
    </xsl:when>
    <xsl:otherwise>
      <xsl:apply-templates mode="RootTemplate" select="$XmlDefinition"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

You can use this code and add your custom XSLT before the <xsl:choose> tag. This approach garantees, that standard list functionality will not be broken.

Also, in your particular situation I'd recommend you to avoid dealing with XSLT at all. You can add title to your list view by setting Chrome Type to "Title Only" in the XsltListViewWebPart properties:

enter image description here

(Site Actions => Edit Page; webpart context menu => Edit Web Part; "Appearance" category)

Autres conseils

By calling only <xsl:apply-templates/> you are not rendering anything after you render list title. In case you are editing some existing OOTB list view replace it with:

<xsl:apply-templates mode="RootTemplate" select="$XmlDefinition"/>  

Where RootTemplate is template that renders 'everything else' and it is missing....

Some more info Use SharePoint Designer 2010 to Create XSLT List View Web Parts

Edited: Removed misleading 2007 references. See @omlin comments and his more specific answer.

Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top