简体   繁体   English

列表视图中的查找字段的自定义xsl呈现(SharePoint 2010)

[英]Custom xsl rendering for lookup field in list view (SharePoint 2010)

I'm trying to change rendering of a list column on list view page. 我正在尝试更改列表视图页面上列表列的呈现。

After a few tutorials and some hair pulling I managed to create an xslt for a calculated and currency field (from fldtypes_XXXXXX.xsl): 经过一些教程和一些头发拉动后,我设法为计算和货币字段创建了一个xslt(来自fldtypes_XXXXXX.xsl):

<xsl:template match ="FieldRef[@Name='MarkCalc']" mode="Text_body">
  <xsl:param name="thisNode" select="."/>
  <xsl:value-of select="$thisNode/@*[name()=current()/@Name]" disable-output-escaping ="yes"/>
</xsl:template>

<xsl:template match="FieldRef[@Name='CurrencyTest']" mode="Number_body">
  <xsl:param name="thisNode" select="."/>
  <b><xsl:value-of disable-output-escaping="yes" select="$thisNode/@*[name()=current()/@Name]" /></b>
</xsl:template>

Then I tried to do the same for a lookup field, but it just won't work. 然后我尝试对查找字段执行相同操作,但它不起作用。 This is my last attempt (I copied it from SharePoint designer). 这是我的最后一次尝试(我从SharePoint设计器复制它)。 What am I missing? 我错过了什么?

<xsl:template match="FieldRef[(@Encoded) and @Name='Lookup1']" mode="Lookup_body">
  <xsl:param name="thisNode" select="."/>
  <b><xsl:value-of select="$thisNode/@*[name()=current()/@Name]" disable-output-escaping="yes" /></b>
</xsl:template>

As it turns out, this is entirely xsl problem. 事实证明,这完全是xsl问题。

Xsl processor chooses template to use based on "match" and "mode" attributes. Xsl处理器根据“匹配”和“模式”属性选择要使用的模板。 When two or more templates match, the one to use is chosen on priority. 当两个或多个模板匹配时,将优先选择要使用的模板。 By default there are three levels of priorities that are assigned based on how specific your match is. 默认情况下,根据匹配的具体方式分配三个级别的优先级。

From http://www.codetoad.com/xml/xslt8.asp : 来自http://www.codetoad.com/xml/xslt8.asp

  • Patterns that match a class of nodes, such as *, which matches all elements, are assigned an implicit priority of -0.5 匹配一类节点的模式(例如*,匹配所有元素)被赋予隐式优先级-0.5

  • Patterns that match nodes according to their name, such as Character, which matches elements, are assigned an implicit priority of 0 根据节点名称匹配节点的模式(如Character,与元素匹配)将被赋予隐式优先级0

  • Patterns that match nodes according to their context, such as CastMember/Character, which matches elements whose parent is a element, are assigned an implicit priority of 0.5 根据其上下文匹配节点的模式(例如CastMember / Character,与父元素为元素的元素匹配)被赋予隐式优先级0.5

When assigning priorities based on patterns, it doesn't matter how specific the context information is: if you specify any context for a node then the template has a priority of 0.5. 在根据模式分配优先级时,上下文信息的具体程度并不重要:如果为节点指定任何上下文,则模板的优先级为0.5。 For example, Description/Link/Character has exactly the same priority as Description//Character. 例如,Description / Link / Character与Description // Character具有完全相同的优先级。

In SharePoint there are two templates for lookup fields 在SharePoint中,有两个用于查找字段的模板

<xsl:template name="FieldRef_Lookup_body" match="FieldRef" mode="Lookup_body" ddwrt:dvt_mode="body">...

and

<xsl:template match="FieldRef[@Encoded]" mode="Lookup_body" ddwrt:dvt_mode="body">

First one has priority 0 (match according to its name), second one has priority 0.5 (match according to context). 第一个优先级为0(根据其名称匹配),第二个优先级为0.5(根据上下文匹配)。

My custom template that should override encoded lookup 我的自定义模板应该覆盖编码查找

<xsl:template match="FieldRef[(@Encoded) and @Name='Lookup1']" mode="Lookup_body">...

also has default priority of 0.5 (remember, "...it doesn't matter how specific the context information is..."), so xsl processor chooses the last one defined(*). 默认优先级为0.5(记住,“......上下文信息的具体程度并不重要......”),因此xsl处理器选择最后一个定义的(*)。

To overcome this you can use attribute priority and set it to higher value than the default template. 要解决此问题,您可以使用属性优先级并将其设置为高于默认模板的值。 In my case, I set it to 1. 就我而言,我把它设置为1。

<xsl:template match="FieldRef[(@Encoded) and @Name='Lookup1']" priority="1" mode="Lookup_body">...



(*) Apparently SharePoint loads custom templates before loading its own. (*)显然SharePoint 加载自己的模板之前加载自定义模板。 Whether this was a choice based on some technical criteria or to ensure I learn xsl, remain mystery. 这是基于某些技术标准的选择还是确保我学习xsl,仍然是个谜。

I had a similar problem, but i was using Sharepoint 2013. In Sharepoint 2013 this is done using clientside rendering, so this method will NOT work. 我有类似的问题,但我使用的是Sharepoint 2013.在Sharepoint 2013中,这是使用客户端渲染完成的,因此这种方法不起作用。 Insted check out http://www.sharepointnutsandbolts.com/2013/01/using-jslink-to-change-ui-of-sharepoint_20.html , or use this ( http://social.msdn.microsoft.com/Forums/sqlserver/en-US/9425e392-26ec-466b-a086-6581e035258f/sharepoint-2013-fldtypesxsl ) method to force server render. Insted退房http://www.sharepointnutsandbolts.com/2013/01/using-jslink-to-change-ui-of-sharepoint_20.html ,或使用此( http://social.msdn.microsoft.com/Forums / sqlserver / en-US / 9425e392-26ec-466b-a086-6581e035258f / sharepoint-2013-fldtypesxsl )强制服务器渲染的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM