SharePoint 2010 Customizing list styles with XSL files
Sometimes we don't want the list to be displayed in the default way, and we want to customize it in a custom way. One way to do this is to use an XSL file.
In the AllItems.aspx page, the list is displayed as a WebPart on the page, the WebPart type is Xsltlistviewwebpart, and when we edit the Web Part, there is a property "xsl link", we define an XSL file , and then put the XSL file link here to complete the task.
Here is my XSL code, save it to the customstyle.xsl file, and copy the file to/_layouts/xsl/.
1 <xsl:stylesheet xmlns:x= "Http://www.w3.org/2001/XMLSchema" xmlns:d= "http://schemas.microsoft.com/sharepoint/ DSP "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:o Ffice:office "version=" 1.0 "exclude-result-prefixes=" xsl msxsl ddwrt "ddwrt:ghost=" Show_all "> 2 <xsl:include href= "/_layouts/xsl/main.xsl"/> 3 <xsl:include href= "/_layouts/xsl/internal.xsl"/> 4 <xsl:output method= "XML" version= "1.0" encoding= "UTF-8" indent= "yes"/> 5 <xsl:output method= "html" indent= "yes"/> 6 <xsl:templ Ate xmlns:x= "Http://www.w3.org/2001/XMLSchema" xmlns:d= "HTTP://SCHEMAS.MICROSOFT.COM/SHAREPOINT/DSP" xmlns:asp= "HTTP://SCHEMAS.MICROSOFT.COM/ASPNET/20" xmlns:__designer= "http://schemas.microsoft.com/WebParts/v2/ Dataview/designer "xmlns:sharepoint=" Microsoft.SharePoint.WebControls "xmlns:o=" Urn:schemas-microsoft-com:office : Office "xmlns:ddwrt=" Http://schemas.microsoft.com/WebParts/v2/DataView/runtime "match="/"ddwrt:ghost=" "> 7 <xsl:variable name= "Rows" select= "/dsqueryresponse/rows/row[$EntityName =" or (position () >= $FirstRow and Position () <= $LastRow)] "/> 8 <table cellpadding=" "cellspacing=" 0 "border=" 0 "width=" 100% "> 9 <xsl:for -each select= "$Rows" > <xsl:call-template name= "Rowview" ></xsl:call-template> </xsl:for-each > <tr> <td colspan= "2" > <xsl:call-template name= "pagingbuttons"/> </td> </tr& Gt </table> </xsl:template> <xsl:template name= "Rowview" > <xsl:variable name= "Thisnode" Select= "." /> <tr> <xsl:if test= "position () mod 2 = 1" &Gt <xsl:attribute name= "class" >ms-alternating</xsl:attribute> </xsl:if> <td class= "Ms-vb" style= "border-bottom:dotted 1px #333;p adding:5px 5px" > Modify the WebPart property to/_layouts/xsl/customstyle.xsl.
Display effect:
This way overrides the default display style for SharePoint.
Sometimes our list has been created a lot, one of the changes is very troublesome, the following write a short code, quickly modify the WebPart properties, if only a few lists or manually modified faster, you can write to the console program according to the situation.
1 SPList LISTDD = web. Lists.trygetlist (list); 2 String dfdf = Listdd. Defaultviewurl; 3 SPFile file = web. GetFile (DFDF); 4 5 splimitedwebpartmanager limitedwebpartmanager = file. Getlimitedwebpartmanager (personalizationscope.shared); 6 splimitedwebpartcollection col = limitedwebpartmanager.webparts; 7 foreach ( System.Web.UI.WebControls.WebParts.WebPart item in col) 8 {9 if (item. GetType (). Name = = "Xsltlistviewwebpart") (item as Basexsltlistwebpart). XSLLink = "/_layouts/xsl/customstyle.xsl"; limitedwebpartmanager.savechanges (item); }14 }
SharePoint 2010 Customizing list styles with XSL files