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

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.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

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)

share|improve this answer
add comment

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.

share|improve this answer
    
I'm afraid the proposed solution will break ManualRefresh property functionality: msdn.microsoft.com/en-us/library/… –  Andrey Markeev Jan 11 '12 at 2:11
    
Sure thing if you are working with 2010. But I tried to cover 2007 version also so I provided 'generic' code and doubled the links :) –  Vedran Rasol Jan 11 '12 at 9:05
    
XsltListViewWebPart is available only starting from SP2010. SP2007 uses DataViewWebPart and generated XSLT, and templates in DVWP have different structure, thus there is no template with mode "RootTemplate" there. –  Andrey Markeev Jan 11 '12 at 9:57
    
It would be unfair to edit my answer now and provide same code you already included. –  Vedran Rasol Jan 11 '12 at 10:39
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.