Best way to show different subset of the data from the same list on the same Site Page?

Answered Best way to show different subset of the data from the same list on the same Site Page?

  • Thursday, May 17, 2012 9:04 PM
     
      Has Code

    Hello,

    I am new to SharePoint 2010, and am facing some weird issues with using Xlstlistviewwebpart to display data from the same list.

    What I needed done:

    I have an Articles list, that stores all kind of articles: ie. Headlines, HR, Dept News etc.

    I have a homepage (.aspx Site Page), that I want to show the latest 5 articles from a few categories: ie. Headlines section, HR news etc.., each category would have a different look. ie. Headlines with pictures, Dept News just as plain links...

    My approach:

    I used a customize Xlstistviewwebpart to achieve this. Since I am showing data from the same list, I simply copied and pasted the same WebPartsPages:XsltListViewWebPart code, except changing the XSL to produce a different HTML output. (See code below).

    My issues:

    Apparently SharePoint 2010 caches the XSL code, and applied the first instance of the XSL to all other xsltlistveiwwebparts, and produced the same HTML formatting (the data is correct to each category though) for each category, even though clearly in my source code they have very different XSL specified. 

    My first guest is that because I copied and pasted the same ___WebPartId="{...}", which presumably confused SharePoint when caching the XSL. 

    So I manually changed the ___WebPartId= so each is different. But of course that didn't fix the problem.

    My questions:

    1. Is there a better solution? ( I only have access via SharePoint 2010 Designer, please no Visual Studio related solutions. Also, articles has to stay in the same list. )

    2. How I can force SharePoint to reset the Xsltlistviewebpart cache? (I don't have server access.)

    3. What is the significance of ___WebPartID? How can I create a valid ID for each one category? (Assuming that will fix the cache, also make the code much more transportable.)

    4. Can we use regular names in the ListName="{1234...1234}" area? ie. ListName="Articles"? This way the code is more transportable.

    <WebPartPages:XsltListViewWebPart runat="server" IsIncluded="True" GhostedXslLink="main.xsl" FrameType="None" NoDefaultStyle="TRUE" ViewFlag="8" Title="Article" PageType="PAGE_NORMALVIEW" ListName="{533A1199-F413-4917-BBCE-056C13AD498C}" Default="FALSE" DisplayName="Articles" __markuptype="vsattributemarkup" partorder="4" __WebPartId="{533A1199-F413-4917-BBCE-056C13A12345}" id="gHighlights" viewcontenttypeid="0x" __designer:customxsl="fldtypes_Ratings.xsl" SuppressWebPartChrome="True" __AllowXSLTEditing="true" WebPart="true" Height="" Width="">
    <XmlDefinition>
    	<View Name="viewHighlights" MobileView="TRUE" Type="HTML" DisplayName="All items" Url="../Lists/Articles/AllItems.aspx" Level="1" BaseViewID="1" ContentTypeID="0x" ImageUrl="/_layouts/images/announce.png" TabularView="FALSE">
    		<Query>
    			<Where>
    				<Eq>
    					<FieldRef Name="ArticleCategory"></FieldRef>
    					<Value Type="Text">Highlights</Value>
    				</Eq>
    			</Where>
    			<OrderBy>
    				<FieldRef Name="PublishDate" Ascending="FALSE">
    				</FieldRef>
    			</OrderBy>
    		</Query>
    		<ViewFields>
    			<FieldRef Name="LinkTitle"/>
    			<FieldRef Name="PublishDate"/>
    			<FieldRef Name="Abstract"/>
    		</ViewFields>
    		<RowLimit Paged="TRUE">4</RowLimit>
    		<Toolbar Type="None"/>
    	</View>
    </XmlDefinition>
    <parameterbindings>
    </parameterbindings><xsl><xsl:stylesheet version="1.0"
    
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    
                  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    
                  xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" 
                  exclude-result-prefixes="msxsl" xmlns:ddwrt2="urn:frontpage:internal" 
                  >
    
      <xsl:output method='html' indent='yes'/>
    
      <xsl:template match='dsQueryResponse'>
    	  <xsl:apply-templates select='Rows/Row'/>
      </xsl:template>
      
      <xsl:template match='Row'>
      	<div class="article">
    	  	<a href="../Lists/Articles/DispForm.aspx?ID={@ID}&Category=Highlights" class="image">
    		  	<xsl:value-of select="@ArticleThumbnail" disable-output-escaping="yes"/>
    		</a>
      		<h3>
        	<a href="../Lists/Articles/DispForm.aspx?ID={@ID}"><xsl:value-of select="@Title" /></a>
        	</h3>
        	<xsl:text> </xsl:text>
        	<p class="meta"><xsl:value-of select="ddwrt:FormatDateTime(@PublishDate, 1033, 'd MMM yyyy')"/></p>
        	
        	<p>
        	<xsl:value-of select="@Abstract" disable-output-escaping="yes"/>
        	<xsl:text> </xsl:text>
        	<a class="readMore" href="../Lists/Articles/DispForm.aspx?ID={@ID}">Read More</a>
        	</p> 
        </div>	
      </xsl:template>
        
    </xsl:stylesheet></xsl></WebPartPages:XsltListViewWebPart>
    

    Thanks for any help,

    Tony

All Replies

  • Friday, May 18, 2012 3:03 AM
     
     

    Tony,

    The ___WebPartId is basically an ID that SP uses to distinguish all web parts within the WebParts table in the SQL database. This is something that SP should generate on the fly and you shouldn't have to specify in the XML. Did you try taking out the attribute altogether and rendering it after making that change?

    Let me know what happens when you do that.

    -Awais

  • Friday, May 18, 2012 5:07 AM
     
     
    Hi Awais,

    I deleted all the ___WebPartID parameters, and when I saved the page, SharePoint re-generated unique IDs for each WebPart.

    Unfortunately this didn't fix the problem. 

    I also tried creating a brand new page, then pasting the same code over (but removing all ___WebPartID so SharePoint can regenerate them). The new page didn't work either, there's no errors. Just the same cache symptom as I described above.

    BTW, I have about 8 WebParts that point to the same list on the homepage. Hopefully that's not exceeding some limit.

    I wonder if the underlying site table is now corrupt, after I tried so many things.

    Any other suggections?

    Thanks,

    Tony
  • Saturday, May 19, 2012 9:47 PM
     
     

    Hey Tony,

    So I think I know what's going on. It's all about the web part IDs. Basically, when you copy your HTML (XSL) for the view and paste it you need to make sure that you're view IDs and web part IDs are unique. So try the following steps:

    1. Generate a new GUID and copy it

    2. Copy the original XSL and make modifications to it

    3. Replace the following GUID attributes with the new GUID you just created:

    • ViewGuid
    • __WebPartId
    • ID (this one has a g_ prefixed to the guid and uses "underscores" instead of "dashes" in the guid
    • In the "View" sub element, the "Name" attribute

    Also give the new web part a unique Title and PartOrder. Even though this is optional, just make that the following attributes are also added to the top-level WebPartPages:XsltListViewWebPart element:

    • ListDisplayName="" 
    • ExportMode="NonSensitiveData" 
    • ListUrl=""

    After making these changes try rendering the web part again. It should solve this problem as I was able to resolve it in my DEV environment.

    Let me know if this helps.

    -Awais

  • Tuesday, May 22, 2012 5:34 AM
     
     
    Hi Awais,

    Thank you very much for spending the time on this.

    I tried to follow what you suggested above, but not yet successful, perhaps I messed a step or two.

    Would you mind copy and pasting one of your test code to share with me? What's the best way to generate a new GUID??

    Also, assuming this method works, the code is not really portable and discourages code reuse (as I originally hoped).

    BTW, I also tried the QueryContentWebPart, which works fine with ItemStyle.XSL. Is there a way to specify inline XSL (like how XsltListViewWebPart does in my question above)? I tried but it seem to just ignored all the inline XSL, and only used the ItemStyle parameter.

    Thanks again!

    Tony
  • Thursday, May 24, 2012 4:37 PM
     
     Answered

    After much research and help from others, it appeared the problem was simply a malformed XSLT:

    In my XSL code: The & need to be escaped as &amp; !! As simple as that.

    This line below:

    <a href="../Lists/Articles/DispForm.aspx?ID={@ID}&Category=Highlights" class="image">

    Need to be changed to:

    <a href="../Lists/Articles/DispForm.aspx?ID={@ID}&amp;Category=Highlights" class="image">

    Also, strictly speaking, 

    ddwrt:FormatDateTime(@PublishDate, 1033, 'd MMM yyyy')

    should be:

    ddwrt:FormatDateTime(string(@PublishDate), 1033, 'd MMM yyyy')

    After I made those changes, the Web Part is working again. Any of the IDs didn't seem matter.

    I wish SharePoint would generate more meaningful errors. At least, if there's anything wrong with the XSLT, don't display any data, leaving the false impression to the developer that the code was OK, and mistakenly think something else is wrong.

    Sigh... 


    • Marked As Answer by Tony Wu 2012 Thursday, May 24, 2012 4:38 PM
    • Edited by Tony Wu 2012 Thursday, May 24, 2012 4:39 PM Addition.
    •