2

I currently have this XSLT added to my list (snippet):

...
<xsl:param name="Today">CurrentDate</xsl:param>
<xsl:template name="FieldRef_printTableCell_EcbAllowed.Due_x0020_Date0" match="FieldRef[@Name='Due_x0020_Date0']" mode="printTableCellEcbAllowed" ddwrt:dvt_mode="body" ddwrt:ghost="" xmlns:ddwrt2="urn:frontpage:internal">
    <xsl:param name="thisNode" select="." />
    <xsl:param name="class" />
    <td>
        <xsl:attribute name="style">
            <xsl:if test="ddwrt:DateTimeTick(ddwrt:GenDisplayName(string($thisNode/@Due_x0020_Date0))) &gt; ddwrt:DateTimeTick(ddwrt:GenDisplayName(string($Today)))" ddwrt:cf_explicit="1">
                    background-color: #FF0000;
            </xsl:if>
...

However, this doesn't work and turns all the non-empty cells in my overdue column to red. What am I missing here?

If it helps, the dates in the column are in this format: m/d/yy

I'm trying to turn the cell red if the task is overdue (based on today's date)


UPDATE: The HTML generated for that particular td is as follows by the way:

<td style="background-color: #FF0000;" class="ms-vb2">
  <nobr>7/29/2014</nobr>
</td>

I'm not sure if the <nobr> tags have something to do with it.

Here's the complete XSLT file

2

I finally got it to work!
In my case, for some reason, there is something wrong with the $Today variable so instead I did this and it worked for me:

<xsl:if test="ddwrt:DateTimeTick(ddwrt:GenDisplayName(string($thisNode/@Due_x0020_Date0)))
                  &lt;= ddwrt:DateTimeTick(ddwrt:GenDisplayName(string(ddwrt:Today())))">
  background-color: #FF0000;
</xsl:if>

Note that I explicitly used ddwrt:Today() instead of $Today.

I'm sure Chris and cubanGuy's answers would have worked had my web part been a data view one instead of a list view. Thanks for you guys' help! It gave me a lot of hints.

| improve this answer | |
1

I have used something similar to what you need:

My XSLT:

<xsl:attribute name="style">
<xsl:if test="ddwrt:DateTimeTick(ddwrt:GenDisplayName(string(@Test))) &lt;  ddwrt:DateTimeTick(ddwrt:GenDisplayName(string($Today)))">background-color: #FF0000;</xsl:if>
</xsl:attribute>

Your XSLT:

<xsl:attribute name="style">
<xsl:if   test="ddwrt:DateTimeTick(ddwrt:GenDisplayName(string($thisNode/@Due_x0020_Date0))) &gt;    ddwrt:DateTimeTick(ddwrt:GenDisplayName(string($Today)))" ddwrt:cf_explicit="1">
    background-color: #FF0000;
</xsl:if>

Pretty much the only major difference I see is that I din't use "$thisNode". By the way @Test refers to Test Due Date.

I hope this helps.

| improve this answer | |
  • This doesn't work for me. Now none of the cells have a red background. I've updated the question in case it helps more. – kei Sep 4 '14 at 21:01
1

It looks like your filter has &gt; (>) instead of &lt;(<)

Wouldn't an overdue task be something in the past and therefore less than today's date?

My xsl looks like CubanGuy's

<td class="ms-vb">
            <xsl:attribute name="style">
                <xsl:if test="ddwrt:DateTimeTick(ddwrt:GenDisplayName(string(@duedate))) &lt; ddwrt:DateTimeTick(ddwrt:GenDisplayName(string($Today)))">background-color: #FF0000;</xsl:if>
            </xsl:attribute>

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

and produces this result (based off today, 9/4): example

and here is html

<td class="ms-vb" style="background-color: rgb(255, 0, 0);">
  Text - 9/1/2014
| improve this answer | |
  • Doesn't work for me. Could you take a look at the pastebin link I've posted in my question? I'm placing this code in the XSL Link parameter of the list view (linked to an external file, not pasted directly to the field). That's probably why I need $thisNode to get anything to get highlighted at all. – kei Sep 4 '14 at 22:20
  • Did you try changing to < in your comparison for date or am I missing the reason for >? Other than that I do not have a lot of experience with item link. I incorrectly assumed this was for a DVWP, so that's about the limit of my usefulness (sorry) – Chris Sep 5 '14 at 12:55

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.