Question

I have a simple list with 3 columns: Title, URL, Color. The Color column is a choose column with two options: yellow or lightgreen. I am using the XSLT List View Web Part .

I am trying to create an xslt file with 1 conditional statement. In simple terms if the value of the item in column color=yellow format the in yellow background; otherwise format it in light green background. I am having trouble with the expression for the xsl:when

Here is the template I am using for the items:

    <xsl:template match="Item">
    <div class="item" style="background-color:lightgreen">
        <xsl:attribute name="onclick">
            window.location = '<xsl:value-of select="URL"/>'
        </xsl:attribute>
        <span class='title'><marquee direction="left" behavior="scroll"><xsl:value-of select="Title"/></marquee></span>
    </div>
</xsl:template>

So I am struggling getting the file to choose between the above and the following:

    <div class="item" style="background-color:lightgreen">
        <xsl:attribute name="onclick">
            window.location = '<xsl:value-of select="URL"/>'
        </xsl:attribute>
        <span class='title'><marquee direction="left" behavior="scroll"><xsl:value-of select="Title"/></marquee></span>
    </div>

Any suggestions appreciated. Maybe there is a simpler way of doing this. I am new to XSLT

Was it helpful?

Solution

Have you considered doing the following:

<xsl:choose>
  <xsl:when test="color='yellow'">
    <xsl:attribute name="style">background-color:yellow</xsl:attribute>
  </xsl:when>
  <xsl:otherwise>
    <xsl:attribute name="style">background-color:lightgreen</xsl:attribute>
  </xsl:otherwise>
</xsl:choose>

You would add this snippet right under the opening .

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top