2

救命啊各位!我的共享点页面中有一个选择字段,其中包含如下选项:

(1) Go
(2) Warning
(3) Stop

现在,我希望它以图标而不是文本的形式出现在列表中。我有一个可以工作的 jquery 脚本,但是在所有列表中搜索包含的文本需要很长时间,而且无论如何使用 xsl 会更好,因为它会在显示之前呈现。

那么我怎样才能在 xsl 中完成这个呢?这是据我所知,因为我只学习 xsl:

<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:ddwrt2="urn:frontpage:internal">

    <!-- Convert the Scope Field into an icon -->
    <xsl:template match="FieldRef[@Name='Scope']">
        <xsl:param name="thisNode" select="."/>
        <xsl:choose>
            <xsl:when test="$thisNode/@Scope='(1) Go'">
                <td class="statusRating1"></td>
            </xsl:when>
            <xsl:when test="$thisNode/@Scope='(2) Warning'">
                <td class="statusRating2"></td>
            </xsl:when>
            <xsl:when test="$thisNode/@Scope='(3) Stop'">
                <td class="statusRating3"></td>
            </xsl:when> 
            <xsl:otherwise>
                <xsl:value-of select="$thisNode/@Scope" />
            </xsl:otherwise>                
        </xsl:choose>
    </xsl:template> 

 </xsl:stylesheet>

这是我要应用的css:

.statusRating1{background-image: url("/_layouts/custom/images/go.png"); }
.statusRating2{background-image: url("/_layouts/custom/images/warning.png"); }
.statusRating3{background-image: url("/_layouts/custom/images/stop.png"); }

现在,我已经尝试过使用和不使用mode="Choice_body"or mode="MultiChoice_bodyand even Text_body,并且也尝试过添加 <xsl:apply-templates /> ,但它似乎从来没有挂钩。该列明确命名为“范围”。也许我只需要添加正确的模式

在萤火虫中,我可以看到从未添加过该类。

[更新]我注意到在我以这种方式使用模板的其他地方,除非模板mode定义正确,否则模板永远不会“采用”。但是,我用谷歌搜索了世界各地,找不到mode用于选择字段的权利。我什至为此创建了一个问题这里。此外,使用thisNode来自Microsoft 的示例,您可以在其中非常轻松地修改字段类型(此处选择字段除外)。

4

2 回答 2

1

为了在属性模板中为 SPFieldChoice 字段定义定义渲染,应使用值主体mode

Choice_body MultiChoice_body未定义具有名称的模式的模板。

因此,在您的情况下,模板将如下所示:

<xsl:template match="FieldRef[@Name='Scope']" mode="body">

没有记录为呈现 SharePoint 字段定义的模板模式属性,但您可以在%ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\LAYOUTS\XSL\fldtypes.xsl. 有关详细信息,请参阅模板PrintField的实现。

希望这可以帮助,

瓦迪姆

于 2012-12-25T13:10:22.693 回答
0

您已经编写了一个模板这一事实还不足以让这个模板永远被执行

如果它被 XSLT 内置(默认)模板的代码选择执行,这些模板不知道任何名为 的参数$thisNode,并且不会将此类参数传递给您的模板。

这意味着$thisNode启动模板时参数的值是空字符串——因此没有满足任何xsl:when测试条件,因此xsl:otherwise选择了。

解决方案

要么

  1. 在您的代码中有一个明确xsl:apply-templates的,它选择要与 tempate 匹配的节点,或者:

  2. 删除<xsl:param>并替换代码中每次出现的$thisNodewith .

于 2012-12-15T04:18:15.617 回答