gpt4 book ai didi

sharepoint - ListView 中查找字段的自定义 xsl 呈现 (SharePoint 2010)

转载 作者:行者123 更新时间:2023-12-04 17:58:49 24 4
gpt4 key购买 nike

我正在尝试更改 ListView 页面上列表列的呈现。

经过一些教程和一些头发拉扯,我设法为计算和货币字段创建了一个 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>

然后我尝试对查找字段执行相同的操作,但它不起作用。这是我的最后一次尝试(我从 SharePoint 设计器复制了它)。我错过了什么?
<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>

最佳答案

事实证明,这完全是 xsl 问题。

Xsl 处理器根据“匹配”和“模式”属性选择要使用的模板。当两个或更多模板匹配时,优先选择要使用的模板。默认情况下,根据匹配的具体程度分配三个级别的优先级。

来自 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

  • Patterns that match nodes according to their name, such as Character, which matches elements, are assigned an implicit priority of 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

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. For example, Description/Link/Character has exactly the same priority as Description//Character.



在 SharePoint 中有两个用于查找字段的模板
<xsl:template name="FieldRef_Lookup_body" match="FieldRef" mode="Lookup_body" ddwrt:dvt_mode="body">...


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

第一个优先级为 0(根据名称匹配),第二个优先级为 0.5(根据上下文匹配)。

我的自定义模板应该覆盖编码查找
<xsl:template match="FieldRef[(@Encoded) and @Name='Lookup1']" mode="Lookup_body">...

还具有 0.5 的默认优先级(请记住,“...上下文信息的具体程度无关紧要...”),因此 xsl 处理器选择最后一个定义的 (*)。

为了克服这个问题,您可以使用属性优先级并将其设置为比默认模板更高的值。就我而言,我将其设置为 1。
<xsl:template match="FieldRef[(@Encoded) and @Name='Lookup1']" priority="1" mode="Lookup_body">...



(*) 显然 SharePoint 在加载自己的模板之前加载自定义模板。这是基于某些技术标准的选择还是确保我学习 xsl,仍然是个谜。

关于sharepoint - ListView 中查找字段的自定义 xsl 呈现 (SharePoint 2010),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2929118/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com