XSL/XSLT - 将value-of作为DIV的样式属性添加

3
我正在使用SharePoint 2010和内容查询Web部件从SharePoint列表中输出日期列表。该列表的显示由名为ItemStyle.xsl的XSL样式表控制。
我已经在一般外观方面取得了进展,但现在想将其检索到的一个字段作为背景/样式属性添加。
我认为我遇到的问题与xsl value-of select在标签末尾有一个闭合括号有关,因此无意中关闭了我的DIV。有人可以查看下面的代码并建议以替代方式打印CategoryColour在开放DIV内。
我还会偶尔在HTML中插入“xmlns:ddwrt”,而我至少希望看到“style:background....”。
非常感谢。
<xsl:stylesheet                                                                                                                                                                                         
  version="1.0"                                                                                                                                                                                         
  exclude-result-prefixes="x d xsl msxsl cmswrt"                                                                                                                                                        
  xmlns:x="http://www.w3.org/2001/XMLSchema"                                                                                                                                                            
  xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"                                                                                                                                                 
  xmlns:cmswrt="http://schemas.microsoft.com/WebParts/v3/Publishing/runtime"                                                                                                                            
  xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"                                                                                                                               
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"                                                                                                                                                      
  xmlns:msxsl="urn:schemas-microsoft-com:xslt">                                                                                                                                                         

<!-- PrettyCal Template -->                                                                                                                                                                             
<xsl:template name="PrettyCal" match="Row[@Style='PrettyCal']" mode="itemstyle">                                                                                                                        
    <xsl:variable name="Start"><xsl:value-of select="@EventDate" /></xsl:variable>                                                                                                                      
    <xsl:variable name="End"><xsl:value-of select="@EndDate" /></xsl:variable>                                                                                                                          
    <xsl:variable name="AllDay"><xsl:value-of select="@AllDayEvent" /></xsl:variable>                                                                                                                   
    <xsl:variable name="Location"><xsl:value-of select="@EventLocation" /></xsl:variable>                                                                                                               
    <xsl:variable name="CategoryColour"><xsl:value-of select="@EventCategoryColour" /></xsl:variable>                                                                                                   

    <div class="upcoming-events" style="background: {CategoryColour}" ><xsl:value-of select="$CategoryColour"/>                                                                                         

        <h2 class="event-title">                                                                                                                                                                        
        <a>                                                                                                                                                                                             
        <xsl:attribute name="onClick">                                                                                                                                                                  
            javascript:SP.UI.ModalDialog.showModalDialog({ url: '/services/marketing/Lists/College%20Calendar/DispForm.aspx?ID=<xsl:value-of select="@ID" />', title: 'Event Details' }); return false; 
        </xsl:attribute>                                                                                                                                                                                
        <xsl:value-of select="@Title" /></a></h2>                                                                                                                                                       

    </div>                                                                                                                                                                                              
</xsl:template>                                                                                                                                                                                         
</xsl:stylesheet>                                                                                                                                                                                       

2个回答

8

您拥有:

  <div class="upcoming-events" style="background: {CategoryColour}" ><xsl:value-of select="$CategoryColour"/>                                                                           

你实际想要的是:

  <div class="upcoming-events" style="background: {$CategoryColour}" ><xsl:value-of select="$CategoryColour"/>                                                                           

我已经尝试过使用$,但它没有起作用。然而,这让我更仔细地检查了我的语法,似乎这才是问题所在。因为我需要传递一个十六进制值,所以我需要使用#,并且最好用分号来关闭属性。 - mtwelve
@mtwelve,我很高兴讨论语法帮助你找到了正确的道路。 - Dimitre Novatchev

2

您的代码中变量CategoryColour前面缺少一个美元符号$


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接