有时候我们不希望列表用默认的方式显示,要我们自定义的方式定制。其中有一种方式是使用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. Android fragment 想activity 传送数据

    fragment可以通过定义 fragment的接口的方法来 想activity传送数据: 而activity则是通过实现 fragment的接口来接收fragment的送来的数据: 1.在fragm ...

  2. SVN与TortoiseSVN实战:属性的奇技淫巧(二)

    硬广:<SVN与TortoiseSVN实战>系列已经写了七篇,本系列结合TortoiseSVN对SVN中容易被忽视的部分进行了详解. 关于属性的奇技淫巧较多,分为两篇来写,第一篇详见< ...

  3. Qt 信号和槽函数

    信号和槽是一种高级接口,应用于对象之间的通信,它是 QT 的核心特性.当某个信号被发射,就需要调用与之相绑定的槽函数.这与Windows下的消息机制类似,消息机制是基于回调函数.一个回调即是一个函数的 ...

  4. CodeSmith 7.01破解下载

    运行CodesmithKeyGenerator.exe,1.修改Prefix输入框的值为:CS70P-2.在主页面点Generate,生成注册码,填入激活码到code smith的Serial框中,( ...

  5. php xml 互相转换

    正好昨天才做过类似的需求……几行代码就可以搞定. 如果你使用 curl 获取的 xml data$xml = simplexml_load_string($data);$data['tk'] = js ...

  6. gulp&gulp-less

    使用gulp-less插件将less文件编译成css,当有less文件发生改变自动编译less,并保证less语法错误或出现异常时能正常工作并提示错误信息. 1.本地安装gulp-less githu ...

  7. Android 弹出框

    1.Java package com.fish.helloworld; import android.app.Activity; import android.app.AlertDialog; imp ...

  8. 第1部分: 游戏引擎介绍, 渲染和构造3D世界

    原文作者:Jake Simpson译者: 向海Email:GameWorldChina@myway.com ---------------------------------------------- ...

  9. PHP开发大型项目的一点经验

    一.变量 最好是把所有的变量存储在一个数组中,这样在程序的开发中可以带来很多的方便,特别是当程序很大的时候.变量的命名就当适合自己的习惯,不管是用拼音还是英语,至少应当有一定的意义,以便适合记忆.变量 ...

  10. Linux FTP服务器搭建与使用

    一.vsftpd说明 LINUX下实现FTP服务的软件很多,最常见的有vsftpd,Wu-ftpd和Proftp等.Red Hat Enterprise Linux中默认安装的是vsftpd. 访问F ...