TPLEE
TPLEE

Reputation: 27

Sharepoint Designer XLST XSL IF/Choose Statement

Can anyone tell me what is wrong with this code I'm using in SharePoint Designer:

<xsl:choose>
    <xsl:when test="number((ddwrt:DateTimeTick(ddwrt:GenDisplayName(string(ddwrt:Today())))- (ddwrt:DateTimeTick(ddwrt:GenDisplayName(string(@Date_x0020_only))))) div 864000000000) &gt;  7 div 864000000000 and &lt;= 14 div 864000000000">
        <h2> <strong><span style="font-size: 8pt"> WEEK 1 </span></strong>
            <xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:whitespace-preserve="yes" xml:space="preserve"> </xsl:text>
        </h2>
    </xsl:when>
</xsl:choose>

It works if I take out the &lt;= 14 div 864000000000 part but I'm essentially trying to label something if it's aged between 7 and <=14 days but can't seem to get this to work.

Here is the error:

SharePoint Designer cannot render the XSLT in this Data View. Try to undo your changes or re-insert the Data View.

Failed setting processor stylesheet : 0x80004005 : Expression expected. number((ddwrt:DateTimeTick(ddwrt:GenDisplayName(string(ddwrt:Today())))- (ddwrt:DateTimeTick(ddwrt:GenDisplayName(string(@Date_x0020_only))))) div 864000000000) > 7 div 864000000000 and --><=<-- 14 div 864000000000

Updated:

Thanks you very much @matthias_h and @Jason Aller

So here is the code I ended up using:

<xsl:variable name="X"   

                        select="number((ddwrt:DateTimeTick(ddwrt:GenDisplayName(
                        string(ddwrt:Today())))-(ddwrt:DateTimeTick(ddwrt:GenDisplayName(
                        string(@Date_x0020_only))))) div 864000000000)">

                </xsl:variable>

            <xsl:if test="$X &gt; 0 div 864000000000 and $X &lt;= 7 div 864000000000">

                <xsl:text> WEEK 1</xsl:text>

            </xsl:if>

            <xsl:if test="$X &gt; 7 div 864000000000 and $X &lt;= 14 div 864000000000">

                <xsl:text> WEEK 2</xsl:text>

            </xsl:if>

            <xsl:if test="$X &gt; 14 div 864000000000 and $X &lt;= 21 div 864000000000">

                <xsl:text> WEEK 3</xsl:text>

            </xsl:if>

            <xsl:if test="$X &gt; 21 div 864000000000">

                <xsl:text> Escalation</xsl:text>

            </xsl:if>

So this works now in the Sharepoint designer preview section it looks like this:

11/7/2014 11:56 AM Escalation

11/7/2014 11:56 AM Escalation 

11/7/2014 11:56 AM Escalation 

11/26/2014 8:47 AM Escalation 

12/18/2014 3:10 PM WEEK 2 

But is showing up in the browser like this:

11/7/2014 11:56 AM Escalation

11/7/2014 11:56 AM Escalation

11/7/2014 11:56 AM Escalation

11/26/2014 8:47 AM Escalation

12/18/2014 3:10 PM Escalation

12/29/2014 1:48 PM Escalation

For some reason its calling them all escalation. Any suggestions?

I really appreciate the help.

Update 2

Thanks @matthias_h

To answer your questions:

1.) Yes it is correct in SPD preview but incorrect in the browser.

2.) This is what the value is in SPD

11/7/2014 11:56 AM Escalation 0.00000000006134259259259259

11/7/2014 11:56 AM Escalation 0.00000000006134259259259259

11/7/2014 11:56 AM Escalation 0.00000000006134259259259259

11/26/2014 8:47 AM Escalation 0.00000000003935185185185185

12/18/2014 3:10 PM WEEK 2  0.000000000013888888888888888

These are what the values look like in Browser

11/7/2014 11:56 AM Escalation 53

11/7/2014 11:56 AM Escalation 53

11/7/2014 11:56 AM Escalation 53

11/26/2014 8:47 AM Escalation 34

12/18/2014 3:10 PM Escalation 12

You think it has something to do with me divided everything by 864000000000?

The reason I did that is becuase it wasn't diplaying the date difference properly in the browser.

So I used this solution: http://sympmarc.com/2013/01/page/2/

Again thanks for the help

Upvotes: 1

Views: 1695

Answers (1)

matthias_h
matthias_h

Reputation: 11416

I can't test the full expression because of missing namespace and functions, but I think there is following syntactical error, just as example:

<xsl:when test="value &gt; 14 and &lt; 7">

should be

<xsl:when test="value &gt; 14 and value &lt; 7">

I suggest - for readability to have the expression in the number() as variable, e.g.

<xsl:variable name="testString"   
      select="number((ddwrt:DateTimeTick(ddwrt:GenDisplayName(
      string(ddwrt:Today())))-(ddwrt:DateTimeTick(ddwrt:GenDisplayName(
      string(@Date_x0020_only))))) div 864000000000)">

and then to check if

<xsl:when test="$testString &gt; 7 div 864000000000 
                and $testString &lt;= 14 div 864000000000">

will work.
Also, if you have no xsl:otherwise or other xsl:when cases, you could adjust to xsl:if instead.

Upvotes: 2

Related Questions