Stump the Panel: SharePoint Q&A

Immediate solutions for common SharePoint questions
It is currently Wed Aug 27, 2014 11:09 pm

All times are UTC - 5 hours [ DST ]


Forum rules


What you are viewing is an archive of Stump the Panel. It remains for reference purposes. Please post all new questions on NothingButSharePoint.com
https://www.nothingbutsharepoint.com/sites/eusp/Forum



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: If else then statements using Xpath
PostPosted: Mon Jan 24, 2011 7:10 am 
Offline

Joined: Sat May 22, 2010 8:14 pm
Posts: 29
Hello all,

I a working on a DVWP in sharepoint designer 2007.

It consist of two date columns A and B. I am trying to have this excel formula work in a formula column using xpath.

=if(A1-B1)>7,"",1)

I have the date subtraction working with help from Marc Andersons Book, but a not sure how the work in the if then else statement.

Regards Michael


Top
 Profile  
 
 Post subject: Re: If else then statements using Xpath
PostPosted: Mon Jan 24, 2011 9:05 am 
Offline
User avatar

Joined: Mon Jan 04, 2010 1:15 am
Posts: 1839
Location: North Carolina
Look at the XSL:Choose functions.


Top
 Profile  
 
 Post subject: Re: If else then statements using Xpath
PostPosted: Thu Jan 27, 2011 12:31 am 
Offline

Joined: Sat May 22, 2010 8:14 pm
Posts: 29
Hi Eric,

Have been reading through Marcs book and I am still confused. My current code is
Code:
</xsl:if>
         <td class="ms-vb">
            <xsl:value-of select="@Proposal_x0020_No_x003a__x0020_P"/>
         </td>
         <td class="ms-vb">
            <xsl:value-of select="ddwrt:FormatDate(string(@AS_x0020_Built_x0020_Report_x002) ,3081 ,1)"/>
         </td>
         <td class="ms-vb">
            <xsl:value-of select="ddwrt:FormatDate(string(@AS_x0020_Built_x0020_Sent_x0020_) ,3081 ,1)"/>
         </td><td class="ms-vb">
            <xsl:value-of select="(ddwrt:FormatDateTime(string(@AS_x0020_Built_x0020_Sent_x0020_),3081,'yyyyMMdd'))-(ddwrt:FormatDateTime(string(@AS_x0020_Built_x0020_Report_x002),1033,'yyyyMMdd'))&gt;
7" /></td></tr>


Which returns a value of True for when the number of days is greater than 7 and false if no date are in either or both columns
What I need is the value to return a Fail if the number of days is greater than 7 and nothing if less than 7 days.

Regards Michael


Top
 Profile  
 
 Post subject: Re: If else then statements using Xpath
PostPosted: Thu Jan 27, 2011 12:56 am 
Offline
User avatar

Joined: Sat Jan 02, 2010 6:02 pm
Posts: 1035
Location: Silver Spring, MD
For that, you'll want to update your code to this:
Code:
<td class="ms-vb">
      <xsl:if test="(ddwrt:FormatDateTime(string(@AS_x0020_Built_x0020_Sent_x0020_),3081,'yyyyMMdd')) - (ddwrt:FormatDateTime(string(@AS_x0020_Built_x0020_Report_x002),1033,'yyyyMMdd')) &gt; 7">
         Fail
      </xsl:if>
</td>

You could use <xsl:choose>, but since you don't want to display anything when it's less than 7 days, it's not necessary.


Top
 Profile  
 
 Post subject: Re: If else then statements using Xpath
PostPosted: Thu Jan 27, 2011 7:58 am 
Offline
User avatar

Joined: Sat Jan 02, 2010 4:29 pm
Posts: 589
Location: Boston, MA, USA
Unfortunately, it's not that simple. Think about the case where your dates are 2010201 and 20100131. The difference there is 70, yet it's actually only a one day difference.

Date arithmetic is problematic! See my blog post here for ways to make this work:
http://sympmarc.com/2009/07/22/date-ari ... int-dvwps/

M.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group