SharePoint 2010 用xsl文件定制列表样式
有时候我们不希望列表用默认的方式显示,要我们自定义的方式定制。其中有一种方式是使用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文件定制列表样式的更多相关文章
- VSTO学习笔记(四)从SharePoint 2010中下载文件
原文:VSTO学习笔记(四)从SharePoint 2010中下载文件 上一次我们开发了一个简单的64位COM加载项,虽然功能很简单,但是包括了开发一个64位COM加载项的大部分过程.本次我们来给CO ...
- SharePoint 2010配置PDF文件全文检索
一.安装Adobe PDF 64 bit IFilter version 9合Adobe Reader 9下载地址: http://www.adobe.com/support/downloads/de ...
- SharePoint 2010 GridView/SPGridView完全应用系统样式
自定义开发页面如果用到了GridView或SPGridView默认跟列表的样式是不一样的,如要要一样,需要: 1)aspx <asp:GridView DataKeyNames="ID ...
- SharePoint 2010 中使用Ztree和EasyUI样式冲突问题
<style type="text/css"> /*解决ztree和SharePoint样式冲突问题*/ .ztree li a { display: inline-b ...
- sharepoint 2010 隐藏左边菜单left menu样式脚本
转:http://www.cfanz.cn/?c=article&a=read&id=60536 在v4.master中,<head></head>标签中,加入 ...
- SharePoint 2010 应用url参数过滤列表视图数据(应用get办法过滤列表数据)
名人名言:读活书,活读书,读书活.——郭沫若 题目其实不知道如何称呼才干合适大师的搜刮习惯.以便有类似题目经由过程百度或google可以搜刮到,其实就是在url后面添加参数过滤显示我们想要的成果,有人 ...
- SharePoint 2010在win7 x64 安装
转:http://kaneboy.blog.51cto.com/1308893/328000 关于<SharePoint 2010应用程序开发指南>,我和杜伟同学正在撰写中,希望下半年早点 ...
- 在 SharePoint 2010 中访问数据
转:http://blog.banysky.net/?p=81001 数据访问的关键方法有哪些? | 使用查询类 | 使用 SPQuery | 使用 SPSiteDataQuery | 使用 LINQ ...
- 自定义和扩展 SharePoint 2010 Server 功能区
了解构成 SharePoint 2010 服务器功能区的组件以及如何通过演练两个功能区自定义项方案来自定义功能区. 适用范围: Microsoft SharePoint Foundation 2010 ...
随机推荐
- Iphone5S 体验(视频+截图)
Iphone5S眨眼从外观看和5区别不大,仔细一看后面,最大的变化还是闪光灯,内部使用了A7的处理器运算速度增强了不少.无论照相还是FaceTime摄像都非常清晰,就连常用的手电筒和动态天气预报都考虑 ...
- Leetcode026. Remove Duplicates from Sorted Array
water class Solution { public: int removeDuplicates(vector<int>& nums) { for(vector<int ...
- WWF3事务和异常处理类型活动<第四篇>
一.FaultHandler 添加一个工作流图如下: 首先添加一个Seruence,在里面添加3个Code,外面添加一个Code,打开Seruence错误处理,在容器里添加一个faultHandler ...
- 【Linux】Linux字体颜色
转自:http://onlyzq.blog.51cto.com/1228/546459 echo显示带颜色,需要使用参数-e格式如下:echo -e "\033[字背景颜色;文字颜色m字符串 ...
- Java 对字符反转操作。
//把一段字符串反转后大小写互换位置 public class test_demo { public static void main(String[] args)throws Exception { ...
- 用python3统计代码行数
今天接到一个电话面试,对方问我在一个项目中维护了多少行代码. 我懵逼了,从来没有统计过啊,怎么还会有这种需求? 当时一脸茫然的想了想,回答了一个,呃...差不多两千多行吧...感觉很心虚 挂完电话之后 ...
- C++ Builder技巧集锦
/* 调用DOS程序时不显示窗口 使 用 ShellExecute调 用 DOS程 序 时 可 以 不 显 示 窗 口 , 如 :*/ ShellExecute(, "open", ...
- css初涉
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- protobuf的使用
Protobuf的安装 正确安装方法: [http://blog.csdn.net/guoyilongedu/article/details/17093811] linux下安装protobuf教程+ ...
- Javascript 补位运算符
看到一个题目~~3.14得到是3,一下子有点蒙,之前在Javascript中完全没有见过~这个运算符.经查才知道~是补位运算符,但是跟原码反码补码又有点不同(在反码这一块,不记正负),好吧,大学的东西 ...