title: XSL / XSLT - Adding a value-of as a style attribute for a DIV
body: <p>I'm using SharePoint 2010 and the Content Query Web Part to output a list of dates from a SharePoint list. The display of this list is controlled by an XSL stylesheet called ItemStyle.xsl</p>
  
  <p>I have made progress with the general appearance but would now like to add one of the fields it retrieves as a background/style attribute.</p>
  
  <p>I believe the problem I am having relates to the xsl value-of select having a closing bracket at the end of the tag and therefore inadvertently closing my DIV. Can someone look at the code below and suggest alternative way of printing the CategoryColour within the opening DIV.</p>
  
  <p>I also will occasional have "xmlns:ddwrt" inserted into the html where I would expect to at least see "style:background...."</p>
  
  <p>Many Thanks</p>
  
  <pre><code>&lt;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"&gt;                                                                                                                                                         
  
  &lt;!-- PrettyCal Template --&gt;                                                                                                                                                                             
  &lt;xsl:template name="PrettyCal" match="Row[@Style='PrettyCal']" mode="itemstyle"&gt;                                                                                                                        
      &lt;xsl:variable name="Start"&gt;&lt;xsl:value-of select="@EventDate" /&gt;&lt;/xsl:variable&gt;                                                                                                                      
      &lt;xsl:variable name="End"&gt;&lt;xsl:value-of select="@EndDate" /&gt;&lt;/xsl:variable&gt;                                                                                                                          
      &lt;xsl:variable name="AllDay"&gt;&lt;xsl:value-of select="@AllDayEvent" /&gt;&lt;/xsl:variable&gt;                                                                                                                   
      &lt;xsl:variable name="Location"&gt;&lt;xsl:value-of select="@EventLocation" /&gt;&lt;/xsl:variable&gt;                                                                                                               
      &lt;xsl:variable name="CategoryColour"&gt;&lt;xsl:value-of select="@EventCategoryColour" /&gt;&lt;/xsl:variable&gt;                                                                                                   
  
      &lt;div class="upcoming-events" style="background: {CategoryColour}" &gt;&lt;xsl:value-of select="$CategoryColour"/&gt;                                                                                         
  
          &lt;h2 class="event-title"&gt;                                                                                                                                                                        
          &lt;a&gt;                                                                                                                                                                                             
          &lt;xsl:attribute name="onClick"&gt;                                                                                                                                                                  
              javascript:SP.UI.ModalDialog.showModalDialog({ url: '/services/marketing/Lists/College%20Calendar/DispForm.aspx?ID=&lt;xsl:value-of select="@ID" /&gt;', title: 'Event Details' }); return false; 
          &lt;/xsl:attribute&gt;                                                                                                                                                                                
          &lt;xsl:value-of select="@Title" /&gt;&lt;/a&gt;&lt;/h2&gt;                                                                                                                                                       
  
      &lt;/div&gt;                                                                                                                                                                                              
  &lt;/xsl:template&gt;                                                                                                                                                                                         
  &lt;/xsl:stylesheet&gt;                                                                                                                                                                                       
  </code></pre>
  
  <p></p>