如何将选择字段的文本转换为图标? [英] How to convert text of choice fields into icons?

查看:60
本文介绍了如何将选择字段的文本转换为图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

药膏,伙计们!我的 sharepoint 页面中有一个选项字段,其中包含如下选项:

Salve, folks! I have a choice field in my sharepoint page with choices like this:

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

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

Now, I want that to appear in the list as an icon instead of text. I have a working jquery script for that, but it takes to long to search through all the list for the contained text, and it would be better to use xsl anyway because it renders before it is displayed.

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

So how can I accomplish this in xsl? Here is as far as I have gotten, as I am only learning 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:

Here is the css I want to apply:

.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/>但它似乎从未上钩.该列明确命名为范围".也许我只需要添加正确的模式?

Now, I've tried this with and without mode="Choice_body" or mode="MultiChoice_body and even Text_body, and have also tried adding <xsl:apply-templates /> but it never even seems to hook. The column is definitely named "Scope". Maybe I just have to add the right mode?

在 firebug 中,我可以看到从未添加过该类.

In firebug, I can see that the class is never added.

[更新] 我注意到在我以这种方式使用模板的其他地方,模板永远不会接受",除非它具有正确的mode定义.但是,我已经在世界各地进行了搜索,但找不到用于选择字段的正确 mode.我什至为那个创建了一个问题,此处.此外,thisNode 的使用来自 Microsoft 的示例,您可以在其中非常轻松地修改字段类型(此处选择字段的情况除外).

[update] I have noticed that in other places where I have used the template in this fashion, that the template never "took" unless it had the correct mode defined. However, I've googled the world over and can't find the right mode to use for a choice field. I even created a question for that, here. Also, the use of thisNode is from Microsoft's examples, where you can modify field types very easily (except in the case of this here choice field).

推荐答案

为了定义 自定义呈现 SPFieldChoicemode 属性模板中的字段应使用值 body

In order to define Custom Rendering for a SPFieldChoice field in template for mode attribute should be used value body

未定义名称为 Choice_body MultiChoice_body 的模式模板.

Template for modes with names Choice_body MultiChoice_body are not defined.

因此,在您的情况下,模板看起来像这样:

So, in your case template would look like this:

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

<小时>

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


Template mode attributes defined for rendering SharePoint fields are not documented, but you could find this information in %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\LAYOUTS\XSL\fldtypes.xsl. See implementation of template PrintField for details.

希望这会有所帮助,

瓦迪姆

这篇关于如何将选择字段的文本转换为图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆