有时候我们不希望列表用默认的方式显示,要我们自定义的方式定制。其中有一种方式是使用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. 感受机房管理化繁为简-新款KVM使用心得

    感受机房管理化繁为简-新款KVM使用心得 一. 背景 随着网络应用的不断增多,各地机房服务器数量也随之增加,利用多传统主机切换器的方式已经无法满足目前这种区域广.设备多人员紧缺的现状,而且即使是使用了 ...

  2. Windows phone 8 学习笔记(2) 数据文件操作(转)

    Windows phone 8 应用用于数据文件存储访问的位置仅仅限于安装文件夹.本地文件夹(独立存储空间).媒体库和SD卡四个地方.本节主要讲解它们的用法以及相关限制性.另外包括本地数据库的使用方式 ...

  3. Loadrunner:安装LR11.0破解步骤及License

    破解步骤: 1.关闭LR相关程序 2.运行LicenseDelete程序,清除LR原来的License 3.将lm70.dll和mlr5lprg.dll这两个文件复制并粘贴到LR安装目录下的bin文件 ...

  4. MyBatis学习系列三——结合Spring

    目录 MyBatis学习系列一之环境搭建 MyBatis学习系列二——增删改查 MyBatis学习系列三——结合Spring MyBatis在项目中应用一般都要结合Spring,这一章主要把MyBat ...

  5. Android IOS WebRTC 音视频开发总结(四九)-- ffmpeg介绍

    本文主要介绍ffmpeg,文章来自博客园RTC.Blacker,支持原创,转载必须说明出处,个人微信公众号blacker,更多详见www.rtc.help 说明: ps1:如果直接从webrtc开始学 ...

  6. Largest palindrome product

    A palindromic number reads the same both ways. The largest palindrome made from the product of two 2 ...

  7. .NET Web开发总结(五)

    7 常用服务器控件 7.1 服务器控件概述 · 服务器控件是指在服务器上执行程序的代码的组件 通常这些服务器控件会提供    给用户一定的界面,  以便用户与服务器之间快速的交互 7.2 HTML 服 ...

  8. sql查看当前周数

    select datepart(wk,cast(getdate() as datetime))

  9. Entity Framework Extended Library (EF扩展类库,支持批量更新、删除、合并多个查询等)

    E文好的可以直接看https://github.com/loresoft/EntityFramework.Extended 也可以在nuget上直接安装这个包 1.先更新VS的NuGet版本http: ...

  10. Knockout.Js官网学习(text绑定)

    前言 text 绑定到DOM元素上,使得该元素显示的文本值为你绑定的参数.该绑定在显示<span>或者<em>上非常有用,但是你可以用在任何元素上. 简单绑定 Today's ...