惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
Vercel News
Vercel News
U
Unit 42
L
LangChain Blog
J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Cloudflare Blog
F
Fortinet All Blogs
小众软件
小众软件
I
InfoQ
P
Proofpoint News Feed
D
DataBreaches.Net
Martin Fowler
Martin Fowler
H
Help Net Security
T
Tailwind CSS Blog
N
Netflix TechBlog - Medium
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
B
Blog RSS Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog

博客园 - jianyi

SpringBoot - open-in-view 机制分析 w3wp CPU 100%问题解决 ShrePoint 迁移域控 SharePoint online 获取文件版本记录 SharePonit online 列表表单定制 VS2015 ionic 开发环境配置纪要 TFS online build change web.config SharePoint 2016 - 安装QuickFlow2013 EF Migrations error: No connection string named 'MpDb' could be found in the application config file. TFS online 自动部署配置 SharePoint Permission Extension SharePoint暂时禁用事件触发 自定义View字段表头 自定义母版页之列表过滤菜单位置issue fix ListDefinition Tips QuickFlow UI 控件之 NamedFormAttachment SharePoint 2010 GridView/SPGridView完全应用系统样式 QuickFlow-如何通过QFD and ExecuteCode获取其他列表数据 DLL嵌入exe中
视图xsl定制之嵌入服务器控件
jianyi · 2014-06-13 · via 博客园 - jianyi

SharePoint 2010 视图 xsl 文件中支持嵌入服务器控件,嵌入服务器控件时,系统先采用xsl将视图xml解析成一个类似UserControl的存在,然后执行UserControl。

代码示例如下:

<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" 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:codeart="CodeArt.SharePoint.SmartQuery"   xmlns:ddwrt2="urn:frontpage:internal">
  <xsl:output method="html" indent="no" encoding="uft-8" />
  <xsl:include href="/_layouts/xsl/main.xsl" />
  <xsl:include href="/_layouts/xsl/internal.xsl" />
  <xsl:decimal-format NaN="" />
  <xsl:template match="/" xmlns:aa="System.Web.UI">
    <xsl:value-of disable-output-escaping="yes" select="'<%@ Register Tagprefix="codeart" Namespace="CodeArt.SharePoint.SmartQuery" Assembly="CodeArt.SharePoint.SmartQuery, Version=1.0.0.0, Culture=neutral, PublicKeyToken=df96d56002e5fe16" %>'"/>
      
    <hr />
    <codeart:XXXWebPart runat="server"/>      
    <hr />
    <xsl:apply-templates mode="RootTemplate" select="$XmlDefinition" />        
    <hr/>
  </xsl:template>
  <xsl:template name="FieldRef_header.ZhuanYe" match="FieldRef[@Name='ZhuanYe']" mode="header">
    <th nowrap="" scope="col" onmouseover="OnChildColumn(this)" class="ms-vh2">
      <div class="ms-vh-div">
        <xsl:copy-of select="current()" />
        专业
        <xsl:value-of select="@DisplayName"/>
      </div>
    </th>
  </xsl:template>
</xsl:stylesheet>

需要注意的是:

并不是所有服务器控件都是可以嵌入xsl的,控件必须继承于WebControl,而不能只继承Control。原因: 

XsltListViewWebPart解析xsl时,嵌入的控件解析成UserControl后,会增加额外的属性,如:

<hr xmlns:aa="System.Web.UI" xmlns:ddwrt2="urn:frontpage:internal" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:x="http://www.w3.org/2001/XMLSchema"、>
<asp:UpdatePanel runat="server" xmlns:asp="http://schemas.microsoft.com/ASPNET/20"><ContentTemplate><asp:Calendar runat="server" xmlns:aa="System.Web.UI" xmlns:ddwrt2="urn:frontpage:internal" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:x="http://www.w3.org/2001/XMLSchema" /></ContentTemplate></asp:UpdatePanel>

这些强制加入的名称控件属性显然不是标准的控件属性,而Control没有实现IAttributeAccessor, 不能任意增加自定义属性,所以会出错,WebControl实现了IAttributeAccessor接口,可以增加任意属性,所有不会出错,以上示例代码中嵌入了UpdatePanel,UpdatePanel直接继承Control,所以会出差。错误信息一般为:

分析器错误 
说明: 在分析向此请求提供服务所需资源时出错。请检查下列特定分析错误详细信息并适当地修改源文件。 
分析器错误消息: 类型“xxx”不具有名为“xmlns:asp”的公共属性。