Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 3rd, 2007, 12:46 PM
Registered User
 
Join Date: Aug 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Basic- Making a template call / Date Arithmetic

I am attempting to do some date arithmetic to assist in some Conditional Formatting on a Sharepoint web site. Disappointingly, this is not straightforward because of the format the dates are returned in. My question (which likely is one of the stupider ones on here) is simply, how exactly do I call a template?

I found a very good template for performing Date Arithmetic here:
http://www.exslt.org/date/functions/...ifference.html

The template syntax is shown to be:
<xsl:call-template name="date:difference">
   <xsl:with-param name="start" select="string" />
   <xsl:with-param name="end" select="string" />
</xsl:call-template>

In a sample xsl file, I have:

=======================
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="date">
<xsl:import href="date.difference.template.xsl" />


<xsl:template match="/">
  <html>
  <body>
  <h2>Date Arithmetic</h2>
  <xsl:apply-templates/>
  </body>
  </html>
</xsl:template>

<xsl:template match="date">
  <br />
  Date: <span style="color:#0000ff">
  <xsl:value-of select="."/>; This is a duration of
<xsl:call-template name="date:difference">
   <xsl:with-param name="start" select="." />
   <xsl:with-param name="end" select="'20070803T00:00:00'" />
</xsl:call-template>
        .</span>
  <br />
</xsl:template>

</xsl:stylesheet>
================================

I have bought Beginning XML and attempting to get up-to-speed, but I think with just a little help I could get my date math implemented and move on to the other parts of my project, for which I also have a steep learning curve. Sorry for the complete newbie question.

presack

Processor: SharePoint 2003/IIS
Desktop OS: Windows XP
 
Old August 3rd, 2007, 01:05 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

There's nothing wrong with your call-template syntax, but the end date is missing hyphens, and I've no idea what format the start date is in. The spec that you cited indicates the permitted formats, I haven't looked at the implementation but it wouldn't surprise me if it does little error checking on the parameters.

Date arithmetic is of course built-in to XSLT 2.0 - but you'll still need to represent dates in ISO format.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 3rd, 2007, 01:33 PM
Registered User
 
Join Date: Aug 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You are correct- I can't believe I missed that. The template does just return a " " string when it encounters an error.

To be honest with you, I am not sure exactly how SharePoint processes its XML. I currently have SharePoint 2003, but will soon have 2007. I will have to do some research to see if it will support XSLT 2.0 so that this will be easier.

Thanks for the quick reply,
presack






Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP date arithmetic takabyte PHP How-To 4 February 12th, 2009 02:54 PM
date arithmetic pcase XSLT 4 June 8th, 2007 09:58 AM
Using Parameter to call another template mikevn123 XSLT 1 October 27th, 2006 03:08 PM
Making a template , Which one is better? studenttwok Beginning PHP 4 July 8th, 2003 10:43 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.