【发布时间】:2012-12-14 23:50:52
【问题描述】:
救命,伙计们!我的共享点页面中有一个选择字段,其中包含如下选项:
(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" 或 mode="MultiChoice_body 甚至 Text_body,并且还尝试添加 <xsl:apply-templates />
但它似乎从来没有上钩过。该列明确命名为“范围”。也许我只需要add the right mode?
在萤火虫中,我可以看到从未添加过该类。
[更新]我注意到,在我以这种方式使用模板的其他地方,除非定义了正确的mode,否则模板永远不会“采用”。但是,我在世界各地搜索过,但找不到合适的 mode 用于选择字段。我什至为 that 创建了一个问题,here。另外,thisNode 的使用来自Microsoft's examples,您可以在其中非常轻松地修改字段类型(此处选择字段除外)。
【问题讨论】:
-
BGM,您编写了一个模板这一事实还不足以让这个模板永远被执行。如果它被 XSLT 内置(默认)模板的代码选择执行,这些模板不知道任何名为
$thisNode的参数,并且不会将此类参数传递给您的模板。这意味着启动模板时参数的值是空字符串——因此xsl:when测试条件都不满足,因此选择xsl:otherwise。
标签: sharepoint xslt