有时候我们不希望列表用默认的方式显示,要我们自定义的方式定制。其中有一种方式是使用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. 详解Ossim 4.3控制台

    在Ossim 4.2以后的发行版中增加了控制台功能下面加以详细说明,当Ossim 启动之后,在控制台以root身份登录系统后会执行ossim-setup脚本,然后显示如下图1所示,了解这些功能,以及操 ...

  2. Android IOS WebRTC 音视频开发总结(四五)-- ORTC背后的真相

    本文主要介绍ORTC(Object Real-time Communication),支持原创,文章来自博客园RTC.Blacker,支持原创,转载必须说明出处,更多详见www.rtc.help. - ...

  3. Android IOS WebRTC 音视频开发总结(三二)-- WebRTC项目开发建议

    本文主要介绍WEBRTC开发过程中的一些现象,文章来自博客园RTC.Blacker,支持原创,欢迎关注微信公众号blacker,更多详见www.rtc.help 随着移动互联网和智能硬件的快速发展,音 ...

  4. Sqlserver2005附加数据库为只读的解决方法

    在sqlserver2005中附加数据库时,附加的数据库会变成只读的,只能进行查询操作. 解决方法 1 打开SqlServer Configuration Manager   开始->Micro ...

  5. Creating a Unique File Name

    If you are working with files or file attachments in PeopleCode, you will typically want to create a ...

  6. CentOS 下如何查看并清理系统内存空间

    有时候在服务器上打开了很多会占用内存的程序但关闭这些程序后,发现内存空间还是和没有关闭应用程序时的占用一样,以致使其它应用程序打开时内存不够或很卡,那么此时就想清理掉以前的程序打开时所占用的内存.而大 ...

  7. mac下,利用homebrew安装PHP+Mysql+Nginx

    具体可以参考直通车 http://blog.frd.mn/install-nginx-php-fpm-mysql-and-phpmyadmin-on-os-x-mavericks-using-home ...

  8. Thinkphp 获取当前url

    $_GET['_URL_'] 获取整个url,返回值是数组 $Think.MODULE_NAME 获取当前class的名称 $Think.ACTION_NAME 获取当前action的方法名称

  9. Library工程No resource identifier found for attribute

    使用library工程中自定义属性无法识别问题 解决:xmlns:ptr="http://schemas.android.com/apk/res/包名, 改成xmlns:ptr=" ...

  10. 双栈排序(codevs 1170)题解

    [问题描述] Tom最近在研究一个有趣的排序问题.如图所示,通过2个栈S1和S2,Tom希望借助以下4种操作实现将输入序列升序排序. 操作a 如果输入序列不为空,将第一个元素压入栈S1 操作b 如果栈 ...