有时候我们不希望列表用默认的方式显示,要我们自定义的方式定制。其中有一种方式是使用xsl文件。

在AllItems.aspx页面中,列表是以webpart的形式显示在页面上的,webpart类型是XsltListViewWebPart,当我们编辑web部件的时候,有一个属性是“XSL 链接”,我们就定义一个xsl文件,然后将xsl的文件链接放到这里就完成任务了。

下面是我的xsl代码,将它保存到customstyle.xsl文件中,将这个文件复制到,/_layouts/xsl/下。

 <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:office:office" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" ddwrt:ghost="show_all">
<xsl:include href="/_layouts/xsl/main.xsl"/>
<xsl:include href="/_layouts/xsl/internal.xsl"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:output method="html" indent="yes"/>
<xsl:template 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="">
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[$EntityName = '' or (position() >= $FirstRow and position() <= $LastRow)]"/>
<table cellpadding="10" cellspacing="0" border="0" width="100%">
<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>
</table>
</xsl:template>
<xsl:template name="RowView">
<xsl:variable name="thisNode" select="."/>
<tr>
<xsl:if test="position() mod 2 = 1">
<xsl:attribute name="class">ms-alternating</xsl:attribute>
</xsl:if>
<td class="ms-vb" style="border-bottom:dotted 1px #333;padding:5px 5px">
<h3 style="padding:0;margin:0;font-size:22px">
<xsl:call-template name="LinkTitleTem"/>
</h3>
<p style="padding:0;margin:0;color:#777">
<span>
<xsl:value-of select="$thisNode/@Author.title" disable-output-escaping="yes"/>
<span style="padding:0 2px">/</span>
<xsl:value-of select="@_x65b0__x95fb__x7c7b__x578b_"/>
<span style="padding:0 2px">/</span>
<xsl:value-of select="ddwrt:FormatDate(string($thisNode/@_x65b0__x95fb__x65f6__x95f4_),2052,3)"/>
</span>
</p>
<div style=" clear:both;height:1px;overflow:hidden;margin-top:-1px"/>
<p style="margin:0px;text-indent:2em;color:#333;font-size:14px;margin-bottom: 5px;line-height: 27px;font-family: Tahoma,'Hiragino Sans Gb','Microsoft YaHei';font-weight: normal;vertical-align: middle;padding-right:20px">
<xsl:value-of select="$thisNode/@_x65b0__x95fb__x7b80__x4ecb_"/>
</p>
<p style="text-align:right;padding-right:30px">
<xsl:call-template name="DocDetails"/>
</p>
</td>
</tr>
</xsl:template>
<xsl:template name="DocDetails">
<xsl:variable name="thisNode" select="."/>
<a>
<xsl:attribute name="href">
<xsl:value-of select="$thisNode/@FileDirRef"/>
customdisp.aspx?id=
<xsl:value-of select="@ID"/>
</xsl:attribute>
<xsl:attribute name="style">
font-size: 12px;font-size: 14px;font-weight: bold;color:#333
</xsl:attribute>
阅读全文
</a>
</xsl:template>
<xsl:template name="LinkTitleTem" ddwrt:ghost="">
<xsl:variable name="thisNode" select="."/>
<a>
<xsl:attribute name="href">
<xsl:value-of select="$thisNode/@FileDirRef"/>
customdisp.aspx?id=
<xsl:value-of select="@ID"/>
</xsl:attribute>
<xsl:attribute name="style">
line-height: 30px;font-size: 16px;color: #333;font-weight: bold;
</xsl:attribute>
<xsl:value-of select="$thisNode/@Title"/>
</a>
</xsl:template>
<xsl:template name="pagingButtons">
<xsl:choose>
<xsl:when test="$XmlDefinition/List/@TemplateType = 106 and $XmlDefinition/@RecurrenceRowset='TRUE'">
<xsl:if test="$dvt_nextpagedata or $dvt_prevpagedata">
<xsl:call-template name="CalendarExpandedRecurrenceFooter"/>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:if test="$XmlDefinition/RowLimit[@Paged='TRUE']">
<xsl:call-template name="CommandFooter">
<xsl:with-param name="FirstRow" select="$FirstRow"/>
<xsl:with-param name="LastRow" select="$LastRow"/>
<xsl:with-param name="dvt_RowCount" select="$dvt_RowCount"/>
</xsl:call-template>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="CommandFooter">
<xsl:param name="FirstRow" select="1"/>
<xsl:param name="LastRow" select="1"/>
<xsl:param name="dvt_RowCount" select="1"/>
<xsl:if test="$FirstRow > 1 or $dvt_nextpagedata">
<xsl:call-template name="Navigation">
<xsl:with-param name="FirstRow" select="$FirstRow"/>
<xsl:with-param name="LastRow" select="$LastRow"/>
<xsl:with-param name="dvt_RowCount" select="$dvt_RowCount"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template xmlns:ddwrt2="urn:frontpage:internal" name="Navigation" ddwrt:ghost="">
<xsl:param name="FirstRow" select="1"/>
<xsl:param name="LastRow" select="1"/>
<xsl:param name="dvt_RowCount" select="1"/>
<xsl:variable name="LastRowValue">
<xsl:choose>
<xsl:when test="$EntityName = '' or $LastRow < $RowTotalCount">
<xsl:value-of select="$LastRow"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$RowTotalCount"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="NextRow">
<xsl:value-of select="$LastRowValue + 1"/>
</xsl:variable>
<table id="bottomPagingCell{$WPQ}" style="font-size:25px;width:100%;padding:5px;" border="0">
<tr>
<td style="width:50%">
<xsl:if test="$dvt_firstrow > 1">
<a>
<xsl:choose>
<xsl:when test="$dvt_RowCount = 0 and not($NoAJAX)">
<xsl:attribute name="onclick">
javascript:RefreshPageTo(event, "
<xsl:value-of select="$PagePath"/>
?
<xsl:value-of select="$ShowWebPart"/>
\u0026
<xsl:value-of select="$FieldSortParam"/>
<xsl:value-of select="$SortQueryString"/>
\u0026View=
<xsl:value-of select="$View"/>
");javascript:return false;
</xsl:attribute>
<xsl:attribute name="href">javascript:</xsl:attribute>
<img src="/_layouts/{$LCID}/images/prev.gif" border="0" alt="{$Rows/@idRewind}"/>
<img src="/_layouts/{$LCID}/images/prev.gif" border="0" alt="{$Rows/@idRewind}"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="RealRowLimit">
<xsl:choose>
<xsl:when test="$XmlDefinition/Query/GroupBy[@Collapse='TRUE']/@GroupLimit">
<xsl:value-of select="$XmlDefinition/Query/GroupBy[@Collapse='TRUE']/@GroupLimit"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$XmlDefinition/RowLimit"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="not($NoAJAX)">
<xsl:attribute name="onclick">
javascript:RefreshPageTo(event, "
<xsl:value-of select="$PagePath"/>
?
<xsl:value-of select="$dvt_prevpagedata"/>
<xsl:value-of select="$ShowWebPart"/>
\u0026PageFirstRow=
<xsl:value-of select="$FirstRow - $RealRowLimit"/>
\u0026
<xsl:value-of select="$FieldSortParam"/>
<xsl:value-of select="$SortQueryString"/>
\u0026View=
<xsl:value-of select="$View"/>
");javascript:return false;
</xsl:attribute>
<xsl:attribute name="href">javascript:</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="href">
javascript:
<xsl:call-template name="GenFireServerEvent">
<xsl:with-param name="param" select="concat('dvt_firstrow={',$FirstRow - $XmlDefinition/RowLimit,'};dvt_startposition={',$dvt_prevpagedata,'}')"/>
</xsl:call-template>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<img src="/_layouts/{$LCID}/images/prev.gif" border="0" alt="{$Rows/@idPrevious}"/>
前一页
</xsl:otherwise>
</xsl:choose>
</a>
</xsl:if>
</td>
<td style="width:50%" align="right">
<xsl:if test="$LastRowValue < $dvt_RowCount or string-length($dvt_nextpagedata)!=0">
<a>
<xsl:choose>
<xsl:when test="not($NoAJAX)">
<xsl:attribute name="onclick">
javascript:RefreshPageTo(event, "
<xsl:value-of select="$PagePath"/>
?
<xsl:value-of select="$dvt_nextpagedata"/>
<xsl:value-of select="$ShowWebPart"/>
\u0026PageFirstRow=
<xsl:value-of select="$NextRow"/>
\u0026
<xsl:value-of select="$FieldSortParam"/>
<xsl:value-of select="$SortQueryString"/>
\u0026View=
<xsl:value-of select="$View"/>
");javascript:return false;
</xsl:attribute>
<xsl:attribute name="href">javascript:</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="href">
javascript:
<xsl:call-template name="GenFireServerEvent">
<xsl:with-param name="param" select="concat('dvt_firstrow={',$NextRow,'};dvt_startposition={',$dvt_nextpagedata,'}')"/>
</xsl:call-template>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
后一页
<img src="/_layouts/{$LCID}/images/next.gif" border="0" alt="{$Rows/@tb_nextpage}"/>
</a>
</xsl:if>
</td>
</tr>
</table>
<xsl:if test="not($GroupingRender)">
<script>
var topPagingCell = document.getElementById("topPagingCell
<xsl:value-of select="$WPQ"/>
"); var bottomPagingCell = document.getElementById("bottomPagingCell
<xsl:value-of select="$WPQ"/>
"); if (topPagingCell != null && bottomPagingCell != null) { topPagingCell.innerHTML = bottomPagingCell.innerHTML; }
</script>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

修改webpart属性为/_layouts/xsl/customstyle.xsl.

显示效果:

这种方式将覆盖SharePoint默认的显示样式。

有的时候我们的列表已经创建了好多,一个一个的修改又很麻烦,下面写了一小段代码,快速的修改webpart属性,如果只有几个列表还是手动修改的比较快,可以根据情况写到控制台程序中。

 SPList listdd = web.Lists.TryGetList(list);
string dfdf = listdd.DefaultViewUrl;
SPFile file = web.GetFile(dfdf); SPLimitedWebPartManager limitedWebPartManager = file.GetLimitedWebPartManager(PersonalizationScope.Shared);
SPLimitedWebPartCollection col = limitedWebPartManager.WebParts;
foreach (System.Web.UI.WebControls.WebParts.WebPart item in col)
{
if (item.GetType().Name == "XsltListViewWebPart")
{
(item as BaseXsltListWebPart).XslLink = "/_layouts/xsl/customstyle.xsl";
limitedWebPartManager.SaveChanges(item);
}
}

SharePoint 2010 用xsl文件定制列表样式的更多相关文章

  1. VSTO学习笔记(四)从SharePoint 2010中下载文件

    原文:VSTO学习笔记(四)从SharePoint 2010中下载文件 上一次我们开发了一个简单的64位COM加载项,虽然功能很简单,但是包括了开发一个64位COM加载项的大部分过程.本次我们来给CO ...

  2. SharePoint 2010配置PDF文件全文检索

    一.安装Adobe PDF 64 bit IFilter version 9合Adobe Reader 9下载地址: http://www.adobe.com/support/downloads/de ...

  3. SharePoint 2010 GridView/SPGridView完全应用系统样式

    自定义开发页面如果用到了GridView或SPGridView默认跟列表的样式是不一样的,如要要一样,需要: 1)aspx <asp:GridView DataKeyNames="ID ...

  4. SharePoint 2010 中使用Ztree和EasyUI样式冲突问题

    <style type="text/css"> /*解决ztree和SharePoint样式冲突问题*/ .ztree li a { display: inline-b ...

  5. sharepoint 2010 隐藏左边菜单left menu样式脚本

    转:http://www.cfanz.cn/?c=article&a=read&id=60536 在v4.master中,<head></head>标签中,加入 ...

  6. SharePoint 2010 应用url参数过滤列表视图数据(应用get办法过滤列表数据)

    名人名言:读活书,活读书,读书活.——郭沫若 题目其实不知道如何称呼才干合适大师的搜刮习惯.以便有类似题目经由过程百度或google可以搜刮到,其实就是在url后面添加参数过滤显示我们想要的成果,有人 ...

  7. SharePoint 2010在win7 x64 安装

    转:http://kaneboy.blog.51cto.com/1308893/328000 关于<SharePoint 2010应用程序开发指南>,我和杜伟同学正在撰写中,希望下半年早点 ...

  8. 在 SharePoint 2010 中访问数据

    转:http://blog.banysky.net/?p=81001 数据访问的关键方法有哪些? | 使用查询类 | 使用 SPQuery | 使用 SPSiteDataQuery | 使用 LINQ ...

  9. 自定义和扩展 SharePoint 2010 Server 功能区

    了解构成 SharePoint 2010 服务器功能区的组件以及如何通过演练两个功能区自定义项方案来自定义功能区. 适用范围: Microsoft SharePoint Foundation 2010 ...

随机推荐

  1. Socket连接

    socket中TCP的三次握手建立连接详解 我们知道tcp建立连接要进行“三次握手”,即交换三个分组.大致流程如下: 客户端向服务器发送一个SYN J 服务器向客户端响应一个SYN K,并对SYN J ...

  2. 代码轮子之很简单但是挺管用的基于C# Task的模拟并发的代码

    代码轮子之很简单但是挺管用的基于C# Task的模拟并发的代码

  3. 1.6Linux设备驱动

    1.设备驱动的作用: 计算机系统的运行是软硬件共同作用的结果.如果应用程序直接访问硬件,会造成应用程序与硬件耦合度过高(了解面向对象的读者会很容易想到,降低对象与对象之间的耦合度最有效的方法是通过接口 ...

  4. javaSE第二十六天

    第二十六天    414 1:网络编程(理解)    414 (1)网络编程:用Java语言实现计算机间数据的信息传递和资源共享    414 (2)网络编程模型    414 (3)网络编程的三要素 ...

  5. 设计模式-代理模式(Proxy)

    应用场景: 领导都有秘书,一般会代理领导的部分职能角色,处理签字.报销.开会等任务.很多新人可能都只知道秘书的存在,毕竟每天与其打交道,不知道领导的存在.但是领导的的确确是真实存在的. 场景说明: 代 ...

  6. URI中的常用属性

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA00AAACDCAIAAADea2ciAAAgAElEQVR4nOz9eTxU////j8/Y930pIb

  7. Sql Server 常用的查询

    基本常用查询 --select select * from student; --all 查询所有 select all sex from student; --distinct 过滤重复 selec ...

  8. Eclipse中Maven的安装

    注:初次尝试安装,配置maven,有错误望指正! 1.说明 maven.rar 是maven文件,解压即可,无需安装,但需要配置环境变量MAVEN_HOME,并放在PATH中,

  9. C# MongoDB--时区问题(差了8小时)

    原因:MongoDB中存储的时间是标准时间UTC +0:00C#的驱动支持一个特性,将实体的时间属性上添加上这个特性并指时区就可以了.例如:[BsonDateTimeOptions(Kind = Da ...

  10. Lua 练习中的Bug 以及日志

    使用 Lua 中的table.getn获得数组的table的长度:运行失败-- > t ={1,2,3 } > print(table.getn(t)) stdin:1: attempt ...