0

I was asked to show top 3 fields of a custom list in sharepoint through xsltlistview webpart. From the help of the blog:http://maulikdhorajia.blogspot.dk/2011/06/sharepoint-2010-xsltlistviewwebpart.html i kind of created the xsl but i have to create headers at the top of each listitem and the background color of the header needs to be taken from the custom list's column: ColorCode. Please anyone help me as i dont know anything about Xslt. how to do dat??

Thanx in advance

my xsl is as follow:

  <td width="33%" valign="top" style="background-color: #F8F6F7">
      <div id="linkitem" class="item">
        <div>


          <a style="font-size: 14pt;font-weight: normal;color: #333333;**background-color:{$color};>**
          <xsl:value-of select="@Title"/>
          </a>
        </div>
        <img style="height:100px; background-color: #F8F6F7">
          <xsl:attribute name="src">
            <xsl:value-of select="@Picture"></xsl:value-of>
          </xsl:attribute>
          <xsl:attribute name="alt">
            <xsl:value-of select="@Title"></xsl:value-of>
          </xsl:attribute>
        </img>
        <div>
          <a style="font-size: 14pt;font-weight: normal;color: #333333">
            <xsl:value-of select="@Name" />
          </a>
        </div>
        <div style="font-size: 8pt;color: #999999;margin-bottom:5px">
          <xsl:value-of select="@Email" />
        </div>
        <div style="font-size: 10pt;color: #333333">
          <xsl:value-of disable-output-escaping="yes" select="@Address" />
        </div>
      </div>
    </td>

</xsl:if>

<xsl:if test="$CurPos = 2">
  <td width="33%" valign="top" style="background-color: #F8F6F7">
    <div id="linkitem" class="item">
      <img style="height:100px; background-color: #F8F6F7">
        <xsl:attribute name="src">
          <xsl:value-of select="@Picture"></xsl:value-of>
        </xsl:attribute>
        <xsl:attribute name="alt">
          <xsl:value-of select="@Title"></xsl:value-of>
        </xsl:attribute>
      </img>
      <div>
        <a style="font-size: 14pt;font-weight: normal;color: #333333">
          <xsl:value-of select="@Name" />
        </a>
      </div>
      <div style="font-size: 8pt;color: #999999;margin-bottom:5px">
        <xsl:value-of select="@Email" />
      </div>
      <div style="font-size: 10pt;color: #333333">
        <xsl:value-of disable-output-escaping="yes" select="@Address" />
      </div>
    </div>
  </td>
</xsl:if>

<xsl:if test="$CurPos = 3">
  <td width="33%" valign="top" style="background-color: #F8F6F7">
    <div id="linkitem" class="item">
      <img style="height:100px; background-color: #F8F6F7">
        <xsl:attribute name="src">
          <xsl:value-of select="@Picture"></xsl:value-of>
        </xsl:attribute>
        <xsl:attribute name="alt">
          <xsl:value-of select="@Title"></xsl:value-of>
        </xsl:attribute>
      </img>
      <div>
        <a style="font-size: 14pt;font-weight: normal;color: #333333">
          <xsl:value-of select="@Name" />
        </a>
      </div>
      <div style="font-size: 8pt;color: #999999;margin-bottom:5px">
        <xsl:value-of select="@Email" />
      </div>
      <div style="font-size: 10pt;color: #333333">
        <xsl:value-of disable-output-escaping="yes" select="@Address" />
      </div>
    </div>
  </td>
</xsl:if>

1

You need to make sure the colour column is included in the columns in your view.

You can then use it in the XSL. eg:

<td width="33%" valign="top" style="background-color: {@ColourCode}">

The curly brackets around the item is a shortcut for:

<xsl:value-of select="@ColourCode" />

Another option is to create the attribute separately:

<td width="33%" valign="top">
 <xsl:attribute name="style">
  background-color: <xsl:value-of select="@ColourCode" />
 </xsl:attribute>
 etc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.