none
Customizing XsltListViewWebPart using vwstyles.xsl, changes are not reflected RRS feed

  • Question

  • Hello

    Recently I decided to improve XsltListViewWebPart for the users, this improvements are related mostly to the toolbar, so for example:

    - Moving the + add document / add new item etc to the top instead of the bottom

    - Creating some buttons at the top even if the toolbar is not shown etc

    By doing some research I found out that the webpart is created by the XSLT file named vwstyles.xsl that you can find in the 14 hive/template/layouts/xsl. Also on msdn I found an article which described how to add customization ( msdn article ). Looks quiet simple by doing that all the xsltlistview webparts will normally reflect the change, what is also the goal of this change is.

    So i created an xsl file named fldtypes_customization.xsl and I put it in the same folder. The file has the following contents:

     <xsl:template name="View_Default_RootTemplate" mode="RootTemplate" match="View" priority="9.0">
        <xsl:param name="ShowSelectAllCheckbox" select="'True'" />
    	
    	<xsl:if test="Toolbar[@Type='Freeform'] or ($MasterVersion=4 and Toolbar[@Type='Standard'])">
          <xsl:call-template name="Freeform">
            <xsl:with-param name="AddNewText">
              <xsl:choose>
                <xsl:when test="List/@TemplateType='104'">
                  <!-- announcement-->
                  <xsl:value-of select="$Rows/@resource.wss.idHomePageNewAnnounce"/>
                </xsl:when>
                <xsl:when test="List/@TemplateType='101' or List/@TemplateType='115'">
                  <!-- doc lib or form lib-->
                  <xsl:value-of select="$Rows/@resource.wss.Add_New_Document"/>
                </xsl:when>
                <xsl:when test="List/@TemplateType='103'">
                  <!-- link -->
                  <xsl:value-of select="$Rows/@resource.wss.AddNewLink"/>
                </xsl:when>
                <xsl:when test="List/@TemplateType='106'">
                  <!-- Event -->
                  <xsl:value-of select="$Rows/@resource.wss.AddNewEvent"/>
                </xsl:when>
                <xsl:when test="List/@TemplateType='119'">
                  <!-- Wiki Library -->
                  <xsl:value-of select="$Rows/@resource.wss.AddNewWikiPage"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="$Rows/@resource.wss.addnewitem"/>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:with-param>
            <xsl:with-param name="ID">
              <xsl:choose>
              <xsl:when test="List/@TemplateType='104'">idHomePageNewAnnouncement</xsl:when>
              <xsl:when test="List/@TemplateType='101'">idHomePageNewDocument</xsl:when>
              <xsl:when test="List/@TemplateType='103'">idHomePageNewLink</xsl:when>
              <xsl:when test="List/@TemplateType='106'">idHomePageNewEvent</xsl:when>
              <xsl:when test="List/@TemplateType='119'">idHomePageNewWikiPage</xsl:when>
              <xsl:otherwise>idHomePageNewItem</xsl:otherwise>
              </xsl:choose>
            </xsl:with-param>
          </xsl:call-template>
        </xsl:if>
    	
    	<table class="ms-menutoolbar" cellpadding="2" cellspacing="0" border="0" width="100%">
          <tr>
            <td class="ms-toolbar" nowrap="nowrap">
              NavigateUp2 
            </td>
    	   </tr>
    	</table>
    	
        <!-- Only if not doing the default view and toolbar type is standard (not freeform or none) name="View_Default_RootTemplate" -->
        <xsl:if test="($IsGhosted = '0' and $MasterVersion=3 and Toolbar[@Type='Standard']) or $ShowAlways">
          <xsl:call-template name="ListViewToolbar"/>
        </xsl:if>
        <table width="100%" cellspacing="0" cellpadding="0" border="0">
          <!-- not show ctx for survey overview-->
          <xsl:if test="not($NoCTX)">
            <xsl:call-template name="CTXGeneration"/>
          </xsl:if>
          <xsl:if test="List/@TemplateType=109">
            <xsl:call-template name="PicLibScriptGeneration"/>
          </xsl:if>
          <tr>
            <td>
              <xsl:if test="not($NoAJAX)">
                <iframe src="javascript:false;" id="FilterIframe{$ViewCounter}" name="FilterIframe{$ViewCounter}" style="display:none" height="0" width="0" FilterLink="{$FilterLink}"></iframe>
              </xsl:if>
              <table summary="{List/@title} {List/@description}" xmlns:o="urn:schemas-microsoft-com:office:office" o:WebQuerySourceHref="{$HttpPath}&amp;XMLDATA=1&amp;RowLimit=0&amp;View={$View}" 
                              width="100%" border="0" cellspacing="0" dir="{List/@Direction}">
                <xsl:if test="not($NoCTX)">
                  <xsl:attribute name="onmouseover">EnsureSelectionHandler(event,this,<xsl:value-of select ="$ViewCounter"/>)</xsl:attribute>
                </xsl:if>
                <xsl:if test="$NoAJAX">
                  <xsl:attribute name="FilterLink">
                    <xsl:value-of select="$FilterLink"/>
                  </xsl:attribute>
                </xsl:if>
                <xsl:attribute name="cellpadding">
                  <xsl:choose>
                    <xsl:when test="ViewStyle/@ID='15' or ViewStyle/@ID='16'">0</xsl:when>
                    <xsl:otherwise>1</xsl:otherwise>
                  </xsl:choose>
                </xsl:attribute>
                <xsl:attribute name="id">
                  <xsl:choose>
                    <xsl:when test="$IsDocLib or dvt_RowCount = 0">onetidDoclibViewTbl0</xsl:when>
                    <xsl:otherwise>
                      <xsl:value-of select="concat($List, '-', $View)"/>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:attribute>
                <xsl:attribute name="class">
                  <xsl:choose>
                    <xsl:when test="ViewStyle/@ID='0' or ViewStyle/@ID='17'"><xsl:value-of select="$ViewClassName"/> ms-basictable</xsl:when>
                    <xsl:otherwise><xsl:value-of select="$ViewClassName"/></xsl:otherwise>
                  </xsl:choose>
                </xsl:attribute>
                <xsl:if test="$InlineEdit">
                  <xsl:attribute name="inlineedit">javascript: <xsl:value-of select="ddwrt:GenFireServerEvent('__cancel;dvt_form_key={@ID}')"/>;CoreInvoke('ExpGroupOnPageLoad', 'true');</xsl:attribute>
                </xsl:if>
                <xsl:apply-templates select="." mode="full">
                  <xsl:with-param name="ShowSelectAllCheckbox" select="$ShowSelectAllCheckbox"/>
                </xsl:apply-templates>
              </table>
                  <xsl:choose>
                    <xsl:when test="$IsDocLib or dvt_RowCount = 0"><script type='text/javascript'>HideListViewRows("onetidDoclibViewTbl0");</script></xsl:when>
                    <xsl:otherwise>
                      <script type='text/javascript'><xsl:value-of select ="concat('HideListViewRows(&quot;', $List, '-', $View, '&quot;);')"/></script>
                    </xsl:otherwise>
                  </xsl:choose>
            </td>
          </tr>
          <xsl:if test="$dvt_RowCount = 0 and not (@BaseViewID='3' and List/@TemplateType='102')">
            <tr>
              <td>
                 <table width="100%" border="0" dir="{List/@Direction}">
                   <xsl:call-template name="EmptyTemplate" />
                 </table>
              </td>
            </tr>
          </xsl:if>
        </table>
        <!-- rowlimit doesn't show page footer-->
        <xsl:call-template name="pagingButtons" />
        
    </xsl:template>

    So as you can see I modified the default roottemplate which builds the outer table, so what I did is: I moved the button to be added at the top and i added a new table with a text "NavigateUp". I saved the changes and performed and IISRESET. And hoping I'll see the changes I reloaded the page, but nothing happened.

    When I open the webpart with SharePoint Designer I can see that the file is added and I see the changes in XSLT I even see them in SPD but not in a real page. And I don't understand why, i did so many modifications and different approaches but no matter what I do, i don't see the change.

    Just also as a side note, SPD behaves strangely, even tho i can see my changes in SPD, but when i modify the file and save it, and do IISRESET, the SPD shows me still the old version of the file, and ONLY after renaming it, it will reflect the changes in SPD, but again nothing happens on the real page.

    I also tried to override the template of the toolbar, which is displayed only when "Show Toolbar" on the xsltlistviewwebpart is set, i only changed the name of the "View", instead of it i put "Custom view" but still nothing is changed! On the page.

    <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">  
      <xsl:template name="ListViewToolbar" priority="9.0">
        <table class="ms-menutoolbar" cellpadding="2" cellspacing="0" border="0" width="100%">
          <tr>
            <td class="ms-toolbar" nowrap="nowrap">
              <SharePoint:NewMenu runat="server"></SharePoint:NewMenu>
            </td>
            <xsl:if test="$IsDocLib">
              <td class="ms-toolbar">|</td>
              <td class="ms-toolbar" nowrap="nowrap">
                <SharePoint:UploadMenu runat="server" />
              </td>
            </xsl:if>
            <td class="ms-toolbar">|</td>
            <td class="ms-toolbar" nowrap="nowrap">
              <SharePoint:ActionsMenu runat="server"></SharePoint:ActionsMenu>
            </td>
            <td class="ms-toolbar">|</td>
            <td class="ms-toolbar" nowrap="nowrap">
              <SharePoint:SettingsMenu runat="server"></SharePoint:SettingsMenu>
            </td>
            <td width="99%" class="ms-toolbar" nowrap="nowrap"/>
            <td nowrap="nowrap" class="ms-toolbar">
              <table border="0" cellpadding="0" cellspacing="0" style="margin-right: 4px">
                <tr>
                  <td class="ms-listheaderlabel" nowrap="nowrap">
                    Custom View:
                    <xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>
                  </td>
                  <td nowrap="nowrap" class="ms-viewselector" id="onetViewSelector" onmouseover="this.className='ms-viewselectorhover'" onmouseout="this.className='ms-viewselector'" runat="server">
                    <SharePoint:ViewSelectorMenu MenuAlignment="Right" AlignToParent="true" runat="server" id="ViewSelectorMenu" />
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
      </xsl:template>
      </xsl:stylesheet>

    So any idea, what am i doing wrong? I really need some advise, because I'm kinda stuck on it.

    Thanks in advance for any input!

    Monday, September 3, 2012 6:02 AM

Answers

  • Hi Shkipperr,

    I find one article that demonstrates the following steps to create a custom view and implement resources in the view:

    1. Create a custom list definition in Microsoft Visual Studio 2010.

    2. Add an XSLT file to the project, and change the XslLink value in Schema.xml so that it references your XSLT file.

    3. Add a resource file to your project that defines resource strings.

    4. Add parameter bindings to the list’s Schema.xml file, and add declarations to your XSLT file to consume the parameters.

    Hope it is helpful to you.

    http://msdn.microsoft.com/en-us/library/ff806164.aspx


    • Edited by Ethan_Chan Thursday, September 6, 2012 6:44 AM
    • Marked as answer by GuYuming Thursday, September 13, 2012 8:56 AM
    Thursday, September 6, 2012 6:44 AM
  • refer to this link

    http://msdn.microsoft.com/en-us/library/ff806164.aspx

    • Marked as answer by GuYuming Thursday, September 13, 2012 8:57 AM
    Friday, September 7, 2012 1:28 PM

All replies

  • So where are you trying to consume this XSLT from?  Are you trying to change the rendering of some OOTB list views or you trying to references this in a a listview webpart that you added to a webpart zone?

    From the type of change you have tried to make it seems to be the former, please confirm this so we can provide the right steps to solve this issue.

    Anand

    Monday, September 3, 2012 6:07 AM
  • Correct, i'm trying to modify the rendering of the OOTB xsltlistviewwebpart. So OOTB webpart consumes this XSLT's and renders the webpart. So no any code that i'm writing or anything, just this XSL templates that i want to override. And this is not to a particular listview webpart it should be applied to all XsltListViewWebparts by default

    On MSDN aritcle they say that custom xsl's are added to the xsl and rendered, if the priority is higher the custom xsl will be rendered instead of the ootb, but it seems it is not the case, or i'm doing something wrong.


    • Edited by Shkipperr Monday, September 3, 2012 7:23 AM
    Monday, September 3, 2012 6:38 AM
  • okay.  So the issue is that just adding some XSLT is one piece of the puzzle.  The second part is making this XSLT available to the list views.

    Option 1

    If you are doing this kind of customization then my recommendation is that you create a custom list definition.  In the list definition you will see where the main.xsl is being referenced by the views (if you search in the definition xml you will find this.)

    You create a copy of main.xsl as main_custom.xsl into which you will reference your other filedtypes or vwstyles.xsl and then replace main.xsl with main_custom.xsl

    The reason I say go with this route is that the DispForm.aspx will be from site definition instead of sitting unghosted in the content database, which is the second option

    Option 2

    The XSLT customization method is still the same as option 1

    You open SPDesigner.  Then you can open the Dispform.aspx that belongs to your list. Again find the XSLT webpart and you will see where it is referencing main.xsl for rendering. Change this reference and save the file. SPDesigner will warn you that you are breaking this from site definition.  
    Accept the warning and save the file.

    Note: Any changes you make to the XSLT files  will require an app pool recycle.  Also as a warning do not modify the OOTB xsl files that are already present there.

    Anand

    • Proposed as answer by Anand . Ramanan Wednesday, September 12, 2012 5:33 PM
    Monday, September 3, 2012 1:36 PM
  • Anand, thank you very much for reply.

    BUT I do not really agree on this options, as they are overhead work.

    Did you check the link which i provide regarding the msdn article how they modify the XLV web part rendering? They do not speak about any of the custom list definitions etc, they just say make an xsl file and put it in the folder and perfrom an IISRESET, that is all.

    As the engine after IISRESET puts whole XSL's together also the custom once and by priority it should execute that template, but something is wrong, my custom xsl's either are not consumed althought i doubt it, as when i open them with SPD i see that they are LIKE present ... although the SPD recognizes them. Or another option something goes wrong with my templating and on the page still the OOTB templates are called.

    I know that modifying OOTB files is a crime, so i never do that, although only for testing it is possible, what i laso did, when i directly modify the vwstyles.xls the changes are reflected on the XLV's.

    Do you know why my approach is not working? What am I doing exactly wrong or is there a bug somewhere in my xls or is it microsoft bug, or it is not ment to be customized like I want to do. I would really like to keep ti simple without the custom list definitions etc etc ...

    So what you think?

    Monday, September 3, 2012 2:08 PM
  • Hi Skipper,

     According to the article, what I gather is that the extensibility goes only as far as modifying the rendering of a particular field type.  So if you wanted to change how your custom field was being displayed on the display forms then you can do that that article is saying, without any overhead.

    However, your requirement talks about adding page elements to the list view rendering that is not scoped any field type.  I do not believe that this is possible using the documented extension paradigm.

    If you find this not to be the case please share with the community the solution.  Also others on the forum might have a better idea.

    Anand

    Monday, September 3, 2012 11:27 PM
  • Hi Shkipperr,

    To customize the XSL, do the following:

      • Open it in sharepoint designer
      • Click the "Advanced Mode" button
      • In the designer window, click on the part of the output you want to change, and make any change to it.  (You could find "Customize XSLT" in the List view tools)


    • Edited by Ethan_Chan Tuesday, September 4, 2012 5:20 AM add picture
    Tuesday, September 4, 2012 3:45 AM
  • Anand, thanks

    So only way is to create a list definition and define there custom main.xsl with reference to custom vwstyles.xsl? Are you really really 100% sure no other way? I did perfrom a lot of research before asking on the forum and i tried quiet some ... but yeah nothing solved the problem.

    Ethan_chan thanks for the response, but that is totaly not what I was looking for, you probably missed the essence of my question. And i knew how to modify the xslt using SPD.

    Tuesday, September 4, 2012 6:53 AM
  • Well, the custom list def method I prescribed is to keep the list forms running from site definition. It is a personal preference. If creating custom list definition is not possible then you are going to have to modify the display form using designer so that you can reference your custom xsl for the view rendering.

    Anand

    Tuesday, September 4, 2012 8:32 AM
  • The problem is that then I will have to modify EVERY XLV webpart, what is not what I want to!

    I need to have this some kind of default way, for every document library for example this changes are applied, what you suggested i will have to create a new list definition based in this case on Document Library and perfrom modification, but then instead of OOTB document library, my custom document library should be used to have the right effect, what also not directly what would want to have, but better than modifying every XLV web part. BUT again what if I want to have also the effect on other list definitions like announcements, team discussions etc ... should i also create for al those a custom list definition?

    Tuesday, September 4, 2012 9:12 AM
  • In that case you can always use jquery to make the modifications you mention.Create your javascript library and include that into the master page.  This way you do not need to modify the xsl

    Wednesday, September 5, 2012 8:34 AM
  • Hi Shkipperr,

    I find one article that demonstrates the following steps to create a custom view and implement resources in the view:

    1. Create a custom list definition in Microsoft Visual Studio 2010.

    2. Add an XSLT file to the project, and change the XslLink value in Schema.xml so that it references your XSLT file.

    3. Add a resource file to your project that defines resource strings.

    4. Add parameter bindings to the list’s Schema.xml file, and add declarations to your XSLT file to consume the parameters.

    Hope it is helpful to you.

    http://msdn.microsoft.com/en-us/library/ff806164.aspx


    • Edited by Ethan_Chan Thursday, September 6, 2012 6:44 AM
    • Marked as answer by GuYuming Thursday, September 13, 2012 8:56 AM
    Thursday, September 6, 2012 6:44 AM
  • refer to this link

    http://msdn.microsoft.com/en-us/library/ff806164.aspx

    • Marked as answer by GuYuming Thursday, September 13, 2012 8:57 AM
    Friday, September 7, 2012 1:28 PM
  • I don't have moderating permission now. but I think I should unmark this
    Thursday, October 10, 2019 8:10 AM