救救吧,伙计们!我的共享点页面中有一个选择字段,其中的选项如下:
(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_body
乃至Text_body
,并且还尝试添加<xsl:apply-templates />
但它似乎从来没有上钩过。该列肯定被命名为“Scope”。也许我只需要添加正确的模式 https://sharepoint.stackexchange.com/questions/54081/what-is-the-xslt-mode-binding-for-a-choice-field?
在 firebug 中,我可以看到该类从未添加。
[update]我注意到,在我以这种方式使用模板的其他地方,模板永远不会“采用”,除非它具有正确的mode
定义的。然而,我用谷歌搜索了全世界,但找不到合适的mode
用于选择字段。我什至创建了一个问题that, here https://sharepoint.stackexchange.com/questions/54081/what-is-the-xslt-mode-binding-for-a-choice-field。另外,使用thisNode
来自微软的例子 http://msdn.microsoft.com/en-us/library/ff606773.aspx?ppud=4,您可以在其中非常轻松地修改字段类型(除了此处选择字段的情况)。