Solved

How can I increment a counter, based on criteria, in my XSL

Posted on 2014-03-10
28
1,102 Views
Last Modified: 2014-03-24
In Classic ASP, I am returning a result set from SQL Server, and using that to build a monthly calendar.  Each calendar day is either blank (white space) or shows the name of the course that the instructor is giving.  When I output the calendar to the screen (which is one month's worth of data, per instructor, in one long row showing the first day of the month through the last day of the month, I would like to display below the instructor's name (first column) a counter that shows the total number of days for that month that have a course associated with it.  The most efficient place to do this is in the XSL when the calendar is being built, because it is already looping through the result set of the SQL query. As the XSL loops through each calendar day, for each instructor, I would like to increment a counter that will show how many courses he will be giving per month, then display that counter, and clear it out for the next instructor.
0
Comment
Question by:avivap
  • 11
  • 9
  • 6
28 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
In general terms that is a bad idea.
Variables in XSLT are like constants.
In order to do what you need, you would need to process the month, recursevely, so call a template with parameters instead of a simple for-each.
That is not too hard but could make your stylesheet cluttered and less clear for later maintenance
Note that in an XSLT you have access to the entire tree of the source document, and it might as well be that you can develop a simple XPath that gives you the total without intermediate "storage" or increment
0
 

Author Comment

by:avivap
Comment Utility
Hi,
Using your comments above, I would like you to send me some sample code of a template with parameters so I can see how to process the month recursively.

(I'm very new to this!)
Thanks.
0
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
Well,

Some data from your end would have helped me to come up with a relevant example.

Here is what I made up

This could be your source
<courses>
    <course teacher="A" month="1" course="foo1"/>
    <course teacher="B" month="1" course="foo2"/>
    <course teacher="A" month="1" course="foo3"/>
    <course teacher="B" month="2" course="foo4"/>
    <course teacher="A" month="2" course="foo5"/>
    <course teacher="B" month="2" course="foo6"/>
    <course teacher="A" month="1" course="foo7"/>
    <course teacher="B" month="3" course="foo8"/>
    <course teacher="A" month="3" course="foo9"/>
    <course teacher="B" month="3" course="foo0"/>
</courses>

Open in new window


And I assume you have some code like this, for teacher A in month 1
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    
    <xsl:template match="/">
        <html>
            <body>
                <xsl:apply-templates/>
            </body>
        </html>
    </xsl:template>
    
    <xsl:template match="courses">
        <table border="1">
            <xsl:for-each select="course[@teacher = 'A'][@month= '1']">
                <tr>
                    <td><xsl:value-of select="@course"/></td>
                </tr>
            </xsl:for-each>
        </table>
        
    </xsl:template>
</xsl:stylesheet>

Open in new window


Note that I recommended NOT too use recursion but use the full expression power of XPath, like this, for a running total

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    
    <xsl:template match="/">
        <html>
            <body>
                <xsl:apply-templates/>
            </body>
        </html>
    </xsl:template>
    
    <xsl:template match="courses">
        <table border="1">
            <xsl:for-each select="course[@teacher = 'A'][@month= '1']">
                <tr>
                    <td><xsl:value-of select="@course"/></td>
                    <td><xsl:value-of select="count(preceding-sibling::course[@teacher = 'A'][@month= '1']) + 1"/></td>
                </tr>
            </xsl:for-each>
        </table>
        
    </xsl:template>
</xsl:stylesheet>

Open in new window


But if you want recursion, here you go (at least you can see the mechanism of passing a parameter to add to a value)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    
    <xsl:template match="/">
        <html>
            <body>
                <xsl:apply-templates/>
            </body>
        </html>
    </xsl:template>
    
    <xsl:template match="courses">
        <table border="1">
            <xsl:call-template name="set-row">
                <xsl:with-param name="teacher" select="'A'"/>
                <xsl:with-param name="month" select="1"/>
                <xsl:with-param name="runningtot" select="0"/>
                <xsl:with-param name="node" select="course[@teacher = 'A'][@month= '1'][1]"/>
            </xsl:call-template>
        </table>
        
    </xsl:template>
    
    <xsl:template name="set-row">
        <xsl:param name="teacher"/>
        <xsl:param name="month"/>
        <xsl:param name="runningtot"/>
        <xsl:param name="node"/>
        <tr>
            <td><xsl:value-of select="$node/@course"/></td>
            <td><xsl:value-of select="$runningtot + 1"/></td>
        </tr>
        <xsl:if test="$node/following-sibling::course[@teacher = $teacher][@month= $month]">
            <xsl:call-template name="set-row">
                <xsl:with-param name="teacher" select="$teacher"/>
                <xsl:with-param name="month" select="$month"/>
                <xsl:with-param name="runningtot" select="$runningtot + 1"/>
                <xsl:with-param name="node" select="$node/following-sibling::course[@teacher = $teacher][@month= $month][1]"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 

Author Comment

by:avivap
Comment Utility
Thank you so much!
I will be in touch and let you know if it worked for me.
0
 

Author Comment

by:avivap
Comment Utility
Ok.
I should have sent the code originally.
Here it is:


<xsl:for-each select="msxsl:node-set($activities)">
                              <xsl:if test="number(translate(startdate, '-', '')) &lt;= number(translate($thisDate, '/', '')) and  number(translate(enddate, '-', '')) &gt;= number(translate($thisDate, '/', ''))">
                                    <xsl:variable name="lngItemID"><xsl:value-of select="activityid" /></xsl:variable>
                                    <xsl:call-template name="ShowActivityForDate">
                                          <xsl:with-param name="lstActivity" select="current()" />
                                          <xsl:value-of select="@Count"/>
                                    </xsl:call-template>
                              </xsl:if>
                        </xsl:for-each>

         </xsl:when>
            <xsl:otherwise>
              <xsl:text>&#160;</xsl:text>
            </xsl:otherwise>
          </xsl:choose>


Basically - if there IS data between the selected dates - like I said, it will place the course name on the calendar for that date.  IF not - the calendar will be white (the otherwise).
However - I want to increment the count - and then I may need help putting it after the instructor's name - but I'm going to try to do it myself!
Is this clearer now?
0
 

Author Comment

by:avivap
Comment Utility
how did the topic area change?
what does "neglected status set" mean?
0
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
Not sure either why this is labelled neglected all of a sudden.

Anyway, I more or less see what you are doing (well, I don't see the entire choose actually)
I leave it up to you to have a first grab at it, but I still feel that alle you need for the total is not recursion but as I said, a simple count of an XPath expression result
0
 
LVL 35

Expert Comment

by:mccarl
Comment Utility
Can you post more of your XSL file?
0
 

Author Comment

by:avivap
Comment Utility
Sure.
here's where the varables are declared in the xsl:




<xsl:for-each select="//record[generate-id(.) = generate-id(key('keyinstructorid', instructorid)[1])]">

                  <xsl:variable name="lnginstructorid"><xsl:value-of select="instructorid" /></xsl:variable>

                  <xsl:variable name="lstinstructor" select="//record[instructorid=$lnginstructorid]" />

                  <xsl:variable name="lstactivities" select="//record[instructorid=$lnginstructorid]"/>

                  <xsl:variable name="countofdays" select="count(//record[instructorid=$lnginstructorid])"/>

I added the variable count of days - because I wanted the count from the previous variable ($lstactivities) - but it's not working.  It's coming up with some random numbers.

(The $lstactivities is in the previous XSL that I've already posted).

Thanks for your help!
0
 
LVL 35

Expert Comment

by:mccarl
Comment Utility
I was hoping that you could provide your entire XSL file. It is very hard to get a good picture of what you are doing with these small, incomplete and essentially unrelated snippets of code.
0
 

Author Comment

by:avivap
Comment Utility
I'm attaching the whole file.
It's LONG!
Thanks.
CTS-Logistics-HD-Cal-Test-EE.xml
0
 

Author Comment

by:avivap
Comment Utility
Hi,
I attached the ENTIRE file last night. But I haven't heard back.
Is ANYONE looking at this????
0
 
LVL 35

Assisted Solution

by:mccarl
mccarl earned 250 total points
Comment Utility
You may need to have a little patience. Your file IS quite long and complex, so it takes a little while to get my head around it.

Try changing the <xsl:for-each> loop that iterates over each "Instructor" (in your displayMonth template) to the following...
<xsl:for-each select="//record[generate-id(.) = generate-id(key('keyinstructorid', instructorid)[1])]">
			<xsl:variable name="lnginstructorid"><xsl:value-of select="instructorid" /></xsl:variable>
			<xsl:variable name="lstinstructor" select="//record[instructorid=$lnginstructorid]" />
			<xsl:variable name="lstactivities" select="//record[instructorid=$lnginstructorid]"/>

    <xsl:variable name="displayWeeksOutput">
        <xsl:call-template name="displayWeeks">
          <xsl:with-param name="year" select="$year"/>
          <xsl:with-param name="month" select="$month"/>
          <xsl:with-param name="week" select="$week-number"/>
          <xsl:with-param name="holidays" select="$holidays"/>
          <xsl:with-param name="keyName" select="'kHoliday'"/>
          <xsl:with-param name="activities" select="$lstactivities"/>
        </xsl:call-template>
    </xsl:variable>

    <xsl:variable name="countofdays" select="count(//msxsl:node-set($displayWeeksOutput)//a)"/>

<tr align="left" bgcolor="white">

<td valign="center" class="tableentry">
	<xsl:element name="a">
		<xsl:attribute name="href">
	 		javascript:OpenMetadata(244,'U','<xsl:value-of select="$lstactivities[1]/instructorid" />','','MDT','width=600,height=650,left=50,top=50,resizable=no');
		</xsl:attribute>
		<xsl:value-of select="$lstactivities[1]/instructor" />
		<xsl:text>(</xsl:text><xsl:value-of select="$countofdays" /><xsl:text>)</xsl:text>
	</xsl:element>	

</td>

        <xsl:copy-of select="$displayWeeksOutput" />

</tr>
</xsl:for-each>

Open in new window

The changes that I have made, just for your understanding, are as follows...

I have moved the execution of the "displayWeeks" template up to the start of the loop. But I have also changed it, so that instead of sending the output of that template directly to the output, it is captured in the "displayWeeksOutput" variable
This then allows us to do some processing on that output, and what I've done is simply count the number of "a" elements, ie. number of links, in that part of the output which should give you the right number since there is 1 link per 1 activity. This is stored in the "countofdays" variable that you were already using
Finally, once we print out the Instructor and their "countofdays" we can just "copy-of" the displayWeeksOutput to the real output, which means the table cell still gets output in the correct place

Let me know how you go and if you have questions on the above.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
I attached the ENTIRE file last night. But I haven't heard back.
Is ANYONE looking at this????

well, I did, but I thought you were

but I'm going to try to do it myself!

Will have a look later today.
Please note we are all volunteers, when in a rush hire a consultant
0
 

Author Comment

by:avivap
Comment Utility
Hi
I tried the changes that were suggested above (by mccari) and they certainly make a lt of sense (thanks for the lesson, I learned alot).
However, I modified my script, etc, AND I'm not receiving an xsl error, however, the page is coming up totally blank - so that's what I'm trying to figure out now!
Thanks for your help.
0
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
Can you post the new XSLT again?
And add a test XML with it?
I can chase it through a debugger to see what hapens
0
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
The XSLT you sent earlier uses a variable $week-number, that is declared out of scope for the call, so that one could not have worked, and with that one you should have seen an XSLT error
0
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
Also there is a statement in mccarls code that is only allowed in XSLT2 (function calls inside path expressions)

                        <xsl:variable name="countofdays" select="count(//msxsl:node-set($displayWeeksOutput)//a)"/>

that one needs to be

                        <xsl:variable name="countofdays" select="count(msxsl:node-set($displayWeeksOutput)//a)"/>

// needs to go in front of the msxsl:node-set
0
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
Here is a variant that functionaly does the same, but is valid XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="script:user">

	<xsl:param name="firstWeekDay" select="0"/>

	<xsl:variable name="n-abbreviatedDOW">
		<day>Mon</day>
		<day>Tue</day>
		<day>Wed</day>
		<day>Thurs</day>
		<day>Fri</day>
		<day>Sat</day>
		<day>Sun</day>
	</xsl:variable>

	<xsl:key name="keyinstructorid" match="record" use="instructorid"/>
	<xsl:variable name="holidays" select="document('Holidays.xml')"/>
	<xsl:key name="kHoliday" match="day" use="concat(../month, ':', .)"/>
	<xsl:variable name="abbreviatedDOW"
		select="document('')/*/xsl:variable[@name='n-abbreviatedDOW']/*"/>

	<xsl:param name="targetyear" select="report/output/record_list/record[1]/year"/>
	<xsl:param name="targetmonth"
		select="format-number(report/output/record_list/record[1]/month,'00')"/>
	<xsl:param name="report" select="report/output/record_list/record[1]/report"/>
	<xsl:param name="report_xsl" select="report/output/record_list/record[1]/report_xsl"/>
	<xsl:param name="targetdate" select="concat($targetyear,'/',$targetmonth,'/01')"/>
	<xsl:param name="today" select="user:today()"/>

	<xsl:template match="/">

		<html>
			<head>

				<style type="text/css">
					.cTContainer{
					    overflow:hidden;
					    padding:2px;
					}
					.cTContainer table{
					    table-layout:fixed;
					}
					.relativeContainer{
					    position:relative;
					    overflow:hidden;
					}
					.fixedTB{
					    position:absolute;
					    z-index:11;
					}
					.leftContainer{
					    position:absolute;
					    overflow:hidden;
					}
					.rightContainer{
					    position:absolute;
					    overflow:hidden;
					}
					.leftSBWrapper{
					    position:relative;
					    z-index:10;
					}
					.topSBWrapper{
					    position:relative;
					    z-index:10;
					    width:100%;
					}
					.SBWrapper{
					    width:100%;
					    overflow:auto;
					}
					
					
					TD.header{
					    font-size:.8em;
					    font-weight:bold;
					    color:#000099;
					    background-color:#ebebeb;
					}
					TD.tableentry{
					    font-size:.7em;
					    font-weight:normal;
					    height:100;
					    border-bottom:solid;
					    border-bottom-width:1px;
					    border-right:solid;
					    border-right-width:1px;
					}
					TD.DOW{
					    font-size:.9em;
					    font-weight:bold;
					    color:#000000;
					    border-bottom:solid;
					    border-bottom-width:1px;
					    border-right:solid;
					    border-right-width:1px;
					}
					TD.monthmove{
					    font-size:.8em;
					    font-weight:bold;
					    color:#000000;
					}
					a.classred{
					    font-size:.8em;
					    font-weight:bold;
					    color:#FF0000;
					}
					a.classblue{
					    font-size:.8em;
					    font-weight:bold;
					    color:#0000FF;
					}
					a.classblack{
					    font-size:.8em;
					    font-weight:bold;
					    color:#000000;
					}
					a.travelok{
					    font-size:.8em;
					    font-weight:bold;
					    color:#036907;
					}
					a.travelred{
					    display:inline;
					    background-color:#FF652B;
					    font-size:.8em;
					    font-weight:bold;
					    color:#000000;
					}
					a.travelgreen{
					    display:inline;
					    background-color:#06FA0E;
					    font-size:.8em;
					    font-weight:bold;
					    color:#000000;
					}
					a.statusblue{
					    font-size:.8em;
					    font-weight:bold;
					    color:#0000FF;
					}
					a.statusyellow{
					    display:inline;
					    background-color:#FDFD03;
					    font-size:10px;
					    font-weight:bold;
					    color:#000000;
					}</style>

				<script src="../../include/js/accel_general.js"/>
				<script src="../../include/js/report_general.js"/>
				<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"/>

				<script>
    $(function() {
        $.fn.cTable = function(o) {        

            this.wrap('<div class="cTContainer"/>');
            this.wrap('<div class="relativeContainer"/>');    
            //Update below template as how you have it in orig table
            var origTableTmpl = '<table border="1" cellspacing="1" cellpadding="5" align="center" width="95%"/>';            
            //get row 1 and clone it for creating sub tables
            var row1 = this.find('tr').slice(0, o.fRows).clone();

            var r1c1ColSpan = 0;
            for (var i = 0; i &lt; o.fCols; i++ ) {
                r1c1ColSpan += this[0].rows[0].cells[i].colSpan;
            }

            //create table with just r1c1 which is fixed for both scrolls
            var tr1c1 = $(origTableTmpl);
            row1.each(function () {            
                var tdct = 0;
                $(this).find('td').filter( function () {
                    tdct += this.colSpan;
                    return tdct &gt; r1c1ColSpan;
                }).remove();                
            });
            row1.appendTo(tr1c1);
            tr1c1.wrap('<div class="fixedTB"/>');
            tr1c1.parent().prependTo(this.closest('.relativeContainer'));

            //create a table with just c1        
            var c1= this.clone().prop({'id': ''});
            c1.find('tr').slice(0, o.fRows).remove();
            c1.find('tr').each(function (idx) {
                var c = 0;
                $(this).find('td').filter(function () {
                    c += this.colSpan;
                    return c &gt; r1c1ColSpan;
                }).remove();           
            });

            var prependRow = row1.first().clone();
            prependRow.find('td').empty();
            c1.prepend(prependRow).wrap('<div class="leftSBWrapper"/>')
            c1.parent().wrap('<div class="leftContainer"/>');            
            c1.closest('.leftContainer').insertAfter('.fixedTB');

            //create table with just row 1 without col 1
            var r1 = $(origTableTmpl);
            row1 = this.find('tr').slice(0, o.fRows).clone();
            row1.each(function () {
                var tds = $(this).find('td'), tdct = 0;
                tds.filter (function () {
                    tdct += this.colSpan;
                    return tdct &lt;= r1c1ColSpan;
                }).remove();
            });
            row1.appendTo(r1);
            r1.wrap('<div class="topSBWrapper"/>')
            r1.parent().wrap('<div class="rightContainer"/>')  
            r1.closest('.rightContainer').appendTo('.relativeContainer');

            $('.relativeContainer').css({'width': 'auto', 'height': o.height});

            this.wrap('<div class="SBWrapper"/>')        
            this.parent().appendTo('.rightContainer');    
            this.prop({'width': o.width});    

            var tw = 0;
            //set width and height of rendered tables
            for (var i = 0; i &lt; o.fCols; i++) {
                tw += $(this[0].rows[0].cells[i]).outerWidth(true);
            }
            tr1c1.width(tw);
            c1.width(tw);

            $('.rightContainer').css('left', tr1c1.outerWidth(true));

            for (var i = 0; i &lt; o.fRows; i++) {
                var tr1c1Ht = $(c1[0].rows[i]).outerHeight(true);
                var thisHt = $(this[0].rows[i]).outerHeight(true);
                var finHt = (tr1c1Ht &gt; thisHt)?tr1c1Ht:thisHt;
                $(tr1c1[0].rows[i]).height(finHt);
                $(r1[0].rows[i]).height(finHt);
            }
            $('.leftContainer').css({'top': tr1c1.outerHeight(true), 'width': tr1c1.outerWidth(true)});

            var rtw = $('.relativeContainer').width() - tw;
            $('.rightContainer').css({'width' : rtw, 'height': o.height, 'max-width': o.width - tw});    

            var trs = this.find('tr');
            trs.slice(1, o.fRows).remove();
            trs.slice(0, 1).find('td').empty();
            trs.each(function () {
                var c = 0;
                $(this).find('td').filter(function () {
                    c += this.colSpan;
                    return c &lt;= r1c1ColSpan;
                }).remove();
            });

            r1.width(this.outerWidth(true));

            for (var i = 1; i &lt; c1[0].rows.length; i++) {
                var c1Ht = $(c1[0].rows[i]).outerHeight(true);
                var thisHt = $(this[0].rows[i]).outerHeight(true);
                var finHt = (c1Ht &gt; thisHt)?c1Ht:thisHt;
                $(c1[0].rows[i]).height(finHt);
                $(this[0].rows[i]).height(finHt);
            }

            $('.SBWrapper').css({'height': $('.relativeContainer').height() - $('.topSBWrapper').height()});            

            $('.SBWrapper').scroll(function () {
                var rc = $(this).closest('.relativeContainer');
                var lfW = rc.find('.leftSBWrapper');
                var tpW = rc.find('.topSBWrapper');

                lfW.css('top', ($(this).scrollTop()*-1));
                tpW.css('left', ($(this).scrollLeft()*-1));        
            });

            $(window).resize(function () {
                $('.rightContainer').width(function () {
                    return $(this).closest('.relativeContainer').outerWidth() - $(this).siblings('.leftContainer').outerWidth();
                });

            });
        }

        $('#cTable').cTable({
            width: 2000,
            height: 500,
            fCols: 1,
            fRows: 1
        });
    });
		</script>
			</head>
			<body>
				<xsl:call-template name="displayMonth">
					<xsl:with-param name="date" select="$targetdate"/>
				</xsl:call-template>
			</body>
		</html>

	</xsl:template>

	<xsl:template name="get-month">
		<xsl:param name="date"/>
		<xsl:variable name="tr-date" select="translate($date, '/', '')"/>
		<xsl:value-of select="substring($tr-date, 5,2)"/>
	</xsl:template>

	<xsl:template name="get-year">
		<xsl:param name="date"/>
		<xsl:variable name="tr-date" select="translate($date, '/', '')"/>
		<xsl:value-of select="substring($tr-date, 1,4)"/>
	</xsl:template>

	<xsl:template name="get-day">
		<xsl:param name="date"/>
		<xsl:variable name="tr-date" select="translate($date, '/', '')"/>
		<xsl:value-of select="substring($tr-date, 7)"/>
	</xsl:template>

	<xsl:template name="displayMonth">
		<xsl:param name="date"/>
		<xsl:variable name="month">
			<xsl:call-template name="get-month">
				<xsl:with-param name="date" select="$date"/>
			</xsl:call-template>
		</xsl:variable>

		<xsl:variable name="year">
			<xsl:call-template name="get-year">
				<xsl:with-param name="date" select="$date"/>
			</xsl:call-template>
		</xsl:variable>

		<xsl:variable name="nameOfMonth"
			select="substring-before(substring-after($default-month-names, concat('[', $month, ']')), '[')"/>
		<xsl:text>&#xA;</xsl:text>

		<xsl:variable name="firstDayOfMonth" select="concat(substring($date, 1, 8), '01')"/>
		<xsl:variable name="week-number">
			<xsl:call-template name="week-number">
				<xsl:with-param name="date" select="$firstDayOfMonth"/>
			</xsl:call-template>
		</xsl:variable>
		
		<center>
			<table border="0" cellpadding="6"
				style="width=100%;border-style:solid;border-width:1px;border-spacing:0;border-collapse:collapse;">
				<tr bgColor="#808080">
					<td class="monthmove" align="left">
						<xsl:call-template name="NextPrevMonthLink">
							<xsl:with-param name="year"
								select="user:DatePart('y',user:DateAdd('m',$targetdate,-1))"/>
							<xsl:with-param name="month"
								select="user:DatePart('m',user:DateAdd('m',$targetdate,-1)) + 1"/>
							<xsl:with-param name="report" select="$report"/>
							<xsl:with-param name="report_xsl" select="$report_xsl"/>
							<xsl:with-param name="nextprev" select="'Previous Month'"/>
						</xsl:call-template>
					</td>
					<td align="center" style="width:100%;">
						<font color="#f8f8f8">
							<strong>
								<xsl:value-of select="$nameOfMonth"/>
								<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
								<xsl:value-of select="$year"/>
							</strong>
						</font>
					</td>
					<td class="monthmove" align="right">
						<xsl:call-template name="NextPrevMonthLink">
							<xsl:with-param name="year"
								select="user:DatePart('y',user:DateAdd('m',$targetdate,1))"/>
							<xsl:with-param name="month"
								select="user:DatePart('m',user:DateAdd('m',$targetdate,1)) + 1"/>
							<xsl:with-param name="report" select="$report"/>
							<xsl:with-param name="report_xsl" select="$report_xsl"/>
							<xsl:with-param name="nextprev" select="'Next Month'"/>
						</xsl:call-template>
					</td>
				</tr>

			</table>
		</center>


		<table border="1" width="95%" cellspacing="1" cellpadding="5" align="center" id="cTable"
			style="border-spacing:0;border-collapse:collapse;">

			<tr>
				<td valign="middle" class="DOW" style="width:70px;"> Instructors </td>

     			<xsl:call-template name="displayWeeksDOW">
					<xsl:with-param name="year" select="$year"/>
					<xsl:with-param name="month" select="$month"/>
					<xsl:with-param name="week" select="$week-number"/>
				</xsl:call-template>

			</tr>

			<xsl:for-each select="//record[generate-id(.) = generate-id(key('keyinstructorid', instructorid)[1])]">
				<xsl:variable name="lnginstructorid"><xsl:value-of select="instructorid" /></xsl:variable>
				<xsl:variable name="lstinstructor" select="//record[instructorid=$lnginstructorid]" />
				<xsl:variable name="lstactivities" select="//record[instructorid=$lnginstructorid]"/>
				
				<xsl:variable name="displayWeeksOutput">
					<xsl:call-template name="displayWeeks">
						<xsl:with-param name="year" select="$year"/>
						<xsl:with-param name="month" select="$month"/>
						<xsl:with-param name="week" select="$week-number"/>
						<xsl:with-param name="holidays" select="$holidays"/>
						<xsl:with-param name="keyName" select="'kHoliday'"/>
						<xsl:with-param name="activities" select="$lstactivities"/>
					</xsl:call-template>
				</xsl:variable>
				
				<xsl:variable name="countofdays" select="count(msxsl:node-set($displayWeeksOutput)//a)"/>
				
				<tr align="left" bgcolor="white">
					
					<td valign="center" class="tableentry">
						<xsl:element name="a">
							<xsl:attribute name="href">
								javascript:OpenMetadata(244,'U','<xsl:value-of select="$lstactivities[1]/instructorid" />','','MDT','width=600,height=650,left=50,top=50,resizable=no');
							</xsl:attribute>
							<xsl:value-of select="$lstactivities[1]/instructor" />
							<xsl:text>(</xsl:text><xsl:value-of select="$countofdays" /><xsl:text>)</xsl:text>
						</xsl:element>	
						
					</td>
					
					<xsl:copy-of select="$displayWeeksOutput" />
					
				</tr>
			</xsl:for-each> 

		</table>

	</xsl:template>

	<xsl:template name="displayWeeksDOW">
		<xsl:param name="year"/>
		<xsl:param name="month"/>
		<xsl:param name="week"/>

		<xsl:variable name="weekStartDate">
			<xsl:call-template name="week-number-to-date">
				<xsl:with-param name="week" select="$week"/>
				<xsl:with-param name="year" select="$year"/>
			</xsl:call-template>
		</xsl:variable>


		<xsl:variable name="dOffset">
			<xsl:choose>
				<xsl:when test="$firstWeekDay = 1">0</xsl:when>
				<xsl:when test="$firstWeekDay = 0">1</xsl:when>
			</xsl:choose>
		</xsl:variable>

		<xsl:for-each select="$abbreviatedDOW">

			<xsl:variable name="thisPos">
				<xsl:choose>
					<xsl:when test="$firstWeekDay = 1">
						<xsl:value-of select="position()"/>
					</xsl:when>
					<xsl:when test="$firstWeekDay = 0">
						<xsl:choose>
							<xsl:when test="position() = 1">7</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="position() - 1"/>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:when>
				</xsl:choose>
			</xsl:variable>

			<xsl:variable name="thisDate">
				<xsl:call-template name="date-add">
					<xsl:with-param name="date" select="$weekStartDate"/>
					<xsl:with-param name="add" select="position() - 1 - $dOffset"/>
				</xsl:call-template>
			</xsl:variable>

			<xsl:variable name="month-of-this-date">
				<xsl:call-template name="get-month">
					<xsl:with-param name="date" select="$thisDate"/>
				</xsl:call-template>
			</xsl:variable>

			<xsl:if test="$month-of-this-date = $month">
				<td align="center" valign="top" class="DOW">
					<xsl:value-of select="$abbreviatedDOW[position() = $thisPos]"/>
				</td>
			</xsl:if>


			<xsl:if test="position() = 7">

				<xsl:variable name="next-week-date">
					<xsl:call-template name="date-add">
						<xsl:with-param name="date" select="$weekStartDate"/>
						<xsl:with-param name="add" select="7 - $dOffset"/>
					</xsl:call-template>
				</xsl:variable>

				<xsl:variable name="month-of-next-week">
					<xsl:call-template name="get-month">
						<xsl:with-param name="date" select="$next-week-date"/>
					</xsl:call-template>
				</xsl:variable>

				<xsl:if test="$month = $month-of-next-week">
					<xsl:call-template name="displayWeeksDOW">
						<xsl:with-param name="year" select="$year"/>
						<xsl:with-param name="month" select="$month"/>
						<xsl:with-param name="week" select="$week + 1"/>
					</xsl:call-template>
				</xsl:if>

			</xsl:if>
		</xsl:for-each>

	</xsl:template>


	<xsl:template name="displayWeeks">
		<xsl:param name="year"/>
		<xsl:param name="month"/>
		<xsl:param name="week"/>
		<xsl:param name="holidays" select="/.."/>
		<xsl:param name="keyName"/>
		<xsl:param name="activities" select="/.."/>

		<xsl:variable name="weekStartDate">
			<xsl:call-template name="week-number-to-date">
				<xsl:with-param name="week" select="$week"/>
				<xsl:with-param name="year" select="$year"/>
			</xsl:call-template>
		</xsl:variable>


		<xsl:variable name="dOffset">
			<xsl:choose>
				<xsl:when test="$firstWeekDay = 1">0</xsl:when>
				<xsl:when test="$firstWeekDay = 0">1</xsl:when>
			</xsl:choose>
		</xsl:variable>

		<xsl:for-each select="$abbreviatedDOW">
			<xsl:variable name="thisDate">
				<xsl:call-template name="date-add">
					<xsl:with-param name="date" select="$weekStartDate"/>
					<xsl:with-param name="add" select="position() - 1 - $dOffset"/>
				</xsl:call-template>
			</xsl:variable>

			<xsl:variable name="month-of-this-date">
				<xsl:call-template name="get-month">
					<xsl:with-param name="date" select="$thisDate"/>
				</xsl:call-template>
			</xsl:variable>

			<xsl:if test="$month-of-this-date = $month">

				<td valign="top" class="tableentry">

					<xsl:variable name="thisDay">
						<xsl:call-template name="get-day">
							<xsl:with-param name="date" select="$thisDate"/>
						</xsl:call-template>
					</xsl:variable>

					<xsl:variable name="holiday">
						<xsl:for-each select="$holidays">
							<xsl:if test="key($keyName, concat($month-of-this-date, ':', $thisDay))">
								<xsl:copy-of
									select="key($keyName, concat($month-of-this-date, ':', $thisDay))/../.."
								/>
							</xsl:if>
						</xsl:for-each>
					</xsl:variable>

					<xsl:variable name="nHoliday" select="msxsl:node-set($holiday)"/>

					<xsl:variable name="aHoliday">
						<xsl:if test="string($nHoliday)"> 1 </xsl:if>
					</xsl:variable>

					<xsl:choose>
						<xsl:when test="$month-of-this-date = $month">
							<xsl:variable name="color">
								<xsl:choose>
									<xsl:when test="$today = $thisDate">
										<xsl:value-of select="'red'"/>
									</xsl:when>
									<xsl:when test="string($aHoliday)">
										<xsl:value-of select="'orange'"/>
									</xsl:when>
									<xsl:when
										test="position() = 7
                                  or (position() = 6 and $firstWeekDay = 1)
                                  or (position() = 1 and $firstWeekDay = 0)">
										<xsl:value-of select="'navy'"/>
									</xsl:when>
									<xsl:otherwise>black</xsl:otherwise>
								</xsl:choose>
							</xsl:variable>

							<xsl:variable name="altText">
								<xsl:if test="string($nHoliday)">
									<xsl:choose>
										<xsl:when test="$nHoliday/*/@name">
											<xsl:value-of select="$nHoliday/*/@name"/>
										</xsl:when>
										<xsl:otherwise>
											<xsl:value-of select="'Unnamed event'"/>
										</xsl:otherwise>
									</xsl:choose>
									<xsl:choose>
										<xsl:when test="$nHoliday/*/@owner">
											<xsl:value-of
												select="concat(' of ', $nHoliday/*/@owner, '.')"/>
										</xsl:when>
										<xsl:otherwise/>
									</xsl:choose>
									<xsl:choose>
										<xsl:when test="$nHoliday/*/firsttime">
											<xsl:variable name="yearsAgo"
												select="$year - $nHoliday/*/firsttime"/>

											<xsl:value-of
												select="concat('&#xA;Happened on this date in ', $nHoliday/*/firsttime, ', ', $yearsAgo, ' years ago.')"
											/>
										</xsl:when>
									</xsl:choose>
								</xsl:if>
							</xsl:variable>

							<font size="3" color="{$color}">
								<xsl:variable name="formattedDay">
									<xsl:choose>
										<xsl:when test="$thisDay &lt; 10">
											<xsl:value-of select="substring($thisDay, 2)"/>
										</xsl:when>
										<xsl:otherwise>
											<strong title="{$altText}">
												<xsl:value-of select="$thisDay"/>
											</strong>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:variable>

								<xsl:choose>
									<xsl:when test="$color = 'navy' or $color = 'orange'">
										<strong title="{$altText}">
											<xsl:value-of select="$formattedDay"/>
										</strong>
									</xsl:when>
									<xsl:otherwise>
										<xsl:value-of select="$formattedDay"/>
									</xsl:otherwise>
								</xsl:choose>
							</font>

							<br/>

							<xsl:for-each select="msxsl:node-set($activities)">
								<xsl:if
									test="number(translate(startdate, '-', '')) &lt;= number(translate($thisDate, '/', '')) and  number(translate(enddate, '-', '')) &gt;= number(translate($thisDate, '/', ''))">
									<xsl:variable name="lngItemID">
										<xsl:value-of select="activityid"/>
									</xsl:variable>
									<xsl:call-template name="ShowActivityForDate">
										<xsl:with-param name="lstActivity" select="current()"/>
									</xsl:call-template>
								</xsl:if>
							</xsl:for-each>


						</xsl:when>
						<xsl:otherwise>
							<xsl:text>&#160;</xsl:text>
						</xsl:otherwise>
					</xsl:choose>

				</td>

			</xsl:if>

			<xsl:if test="position() = 7">
				<xsl:variable name="next-week-date">
					<xsl:call-template name="date-add">
						<xsl:with-param name="date" select="$weekStartDate"/>
						<xsl:with-param name="add" select="7 - $dOffset"/>
					</xsl:call-template>
				</xsl:variable>

				<xsl:variable name="month-of-next-week">
					<xsl:call-template name="get-month">
						<xsl:with-param name="date" select="$next-week-date"/>
					</xsl:call-template>
				</xsl:variable>

				<xsl:if test="$month = $month-of-next-week">
					<xsl:call-template name="displayWeeks">
						<xsl:with-param name="year" select="$year"/>
						<xsl:with-param name="month" select="$month"/>
						<xsl:with-param name="week" select="$week + 1"/>
						<xsl:with-param name="holidays" select="$holidays"/>
						<xsl:with-param name="keyName" select="$keyName"/>
						<xsl:with-param name="activities" select="$activities"/>
					</xsl:call-template>
				</xsl:if>
			</xsl:if>
		</xsl:for-each>

	</xsl:template>

	<xsl:template name="ShowActivityForDate">

		<xsl:param name="lstActivity"/>
		<xsl:choose>
			<xsl:when test="$lstActivity/type = 5239">
				<xsl:element name="a">
					<xsl:attribute name="href"> javascript:OpenMetadataExt(225,'MDT',<xsl:value-of
							select="$lstActivity/xrefid"
							/>,'660,777,662,661,766,765,480,778,780,779,365','MDT','width=700,height=450,left=50,top=50,resizable=yes',222,4,<xsl:value-of
							select="$lstActivity/activityid"/>,659,'_blank'); </xsl:attribute>
					<xsl:attribute name="class">classblack</xsl:attribute>
					<xsl:value-of select="$lstActivity/customer"/>
					<br/>
					<xsl:value-of select="$lstActivity/location"/>
					<br/>
					<xsl:value-of select="$lstActivity/workorder"/>
				</xsl:element>
			</xsl:when>
			<xsl:when
				test="$lstActivity/type = 5240 and $lstActivity/type1 = 5245 and $lstActivity/type2 = 4617">
				<xsl:element name="a">
					<xsl:attribute name="href"> javascript:OpenMetadataExt(225,'MDT',<xsl:value-of
							select="$lstActivity/xrefid"
							/>,'660,777,662,661,766,765,480,778,780,779,365','MDT','width=700,height=450,left=50,top=50,resizable=yes',222,4,<xsl:value-of
							select="$lstActivity/activityid"/>,659,'_blank'); </xsl:attribute>
					<xsl:attribute name="class">travelgreen</xsl:attribute>
					<xsl:value-of select="$lstActivity/customer"/><br/>
					<xsl:value-of select="$lstActivity/location"/><br/>
					<xsl:value-of select="$lstActivity/workorder"/><br/>Travel <xsl:value-of
						select="$lstActivity/mode"/>
				</xsl:element>
			</xsl:when>
			<xsl:when
				test="$lstActivity/type = 5240 and $lstActivity/type1 = 5245 and $lstActivity/type2 = 5244">
				<xsl:element name="a">
					<xsl:attribute name="href"> javascript:OpenMetadataExt(225,'MDT',<xsl:value-of
							select="$lstActivity/xrefid"
							/>,'660,777,662,661,766,765,480,778,780,779,365','MDT','width=700,height=450,left=50,top=50,resizable=yes',222,4,<xsl:value-of
							select="$lstActivity/activityid"/>,659,'_blank'); </xsl:attribute>
					<xsl:attribute name="class">travelgreen</xsl:attribute>
					<xsl:value-of select="$lstActivity/customer"/><br/>
					<xsl:value-of select="$lstActivity/location"/><br/>
					<xsl:value-of select="$lstActivity/workorder"/><br/>Travel <xsl:value-of
						select="$lstActivity/mode"/>
				</xsl:element>
			</xsl:when>
			<xsl:when test="$lstActivity/type = 5240 and $lstActivity/type1 = 5242">
				<xsl:element name="a">
					<xsl:attribute name="href"> javascript:OpenMetadataExt(225,'MDT',<xsl:value-of
							select="$lstActivity/xrefid"
							/>,'660,777,662,661,766,765,480,778,780,779,365','MDT','width=700,height=450,left=50,top=50,resizable=yes',222,4,<xsl:value-of
							select="$lstActivity/activityid"/>,659,'_blank'); </xsl:attribute>
					<xsl:attribute name="class">travelred</xsl:attribute>
					<xsl:value-of select="$lstActivity/customer"/><br/>
					<xsl:value-of select="$lstActivity/location"/><br/>
					<xsl:value-of select="$lstActivity/workorder"/><br/>Travel <xsl:value-of
						select="$lstActivity/mode"/>
				</xsl:element>
			</xsl:when>
			<xsl:when test="$lstActivity/type = 5240 and $lstActivity/type2 = 4616">
				<xsl:element name="a">
					<xsl:attribute name="href"> javascript:OpenMetadataExt(225,'MDT',<xsl:value-of
							select="$lstActivity/xrefid"
							/>,'660','MDT','width=700,height=450,left=50,top=50,resizable=yes',222,4,<xsl:value-of
							select="$lstActivity/activityid"/>,659,'_blank'); </xsl:attribute>
					<xsl:attribute name="class">travelred</xsl:attribute>
					<xsl:value-of select="$lstActivity/customer"/><br/>
					<xsl:value-of select="$lstActivity/location"/><br/>
					<xsl:value-of select="$lstActivity/workorder"/><br/>Travel <xsl:value-of
						select="$lstActivity/mode"/>
				</xsl:element>
			</xsl:when>
			<xsl:when
				test="$lstActivity/type = 5240 and $lstActivity/type1 = 5243 and $lstActivity/type2 = 4617">
				<xsl:element name="a">
					<xsl:attribute name="href"> javascript:OpenMetadataExt(225,'MDT',<xsl:value-of
							select="$lstActivity/xrefid"
							/>,'660','MDT','width=700,height=450,left=50,top=50,resizable=yes',222,4,<xsl:value-of
							select="$lstActivity/activityid"/>,659,'_blank'); </xsl:attribute>
					<xsl:attribute name="class">travelgreen</xsl:attribute>
					<xsl:value-of select="$lstActivity/customer"/><br/>
					<xsl:value-of select="$lstActivity/location"/><br/>
					<xsl:value-of select="$lstActivity/workorder"/><br/>Travel <xsl:value-of
						select="$lstActivity/mode"/>
				</xsl:element>
			</xsl:when>

			<xsl:when test="$lstActivity/type = 4624">
				<xsl:element name="a">
					<xsl:attribute name="class">statusblue</xsl:attribute>
					<xsl:value-of select="$lstActivity/course"/>
				</xsl:element>
			</xsl:when>
			<xsl:when test="$lstActivity/type = 4623">
				<xsl:element name="a">
					<xsl:attribute name="class">statusblue</xsl:attribute>
					<xsl:value-of select="$lstActivity/course"/>
				</xsl:element>
			</xsl:when>
			<xsl:when test="$lstActivity/type = 4625">
				<xsl:element name="a">
					<xsl:attribute name="class">statusblue</xsl:attribute>
					<xsl:value-of select="$lstActivity/course"/>
				</xsl:element>
			</xsl:when>
			<xsl:when test="$lstActivity/type = 5246">
				<xsl:element name="a">
					<xsl:attribute name="class">statusyellow</xsl:attribute>
					<xsl:value-of select="$lstActivity/course"/>
				</xsl:element>
			</xsl:when>


			<xsl:otherwise> </xsl:otherwise>
		</xsl:choose>

		<br/>
	</xsl:template>

	<xsl:template name="NextPrevMonthLink">
		<xsl:param name="year"/>
		<xsl:param name="month"/>
		<xsl:param name="report"/>
		<xsl:param name="report_xsl"/>
		<xsl:param name="nextprev"/>
		<xsl:element name="a">
			<xsl:attribute name="href"> ../export.asp?fm=3&amp;rt=<xsl:value-of select="$report"
					/>&amp;xsl=<xsl:value-of select="$report_xsl"
					/>.xsl&amp;criteria=vCAL|<xsl:value-of select="$report"/>:vXSLCAL|<xsl:value-of
					select="$report_xsl"/>:vYear|<xsl:value-of select="$year"/>:vMonth|<xsl:value-of
					select="$month"/>
			</xsl:attribute>
			<xsl:value-of select="$nextprev"/>
		</xsl:element>
	</xsl:template>

	<!-- ========================================================================== -->
	<!-- =======================PROCEED AT YOUR OWN RISK=========================== -->
	<!-- ========================================================================== -->

	<msxsl:script implements-prefix="user"> function today() { var d, s = ""; d = new Date(); s +=
		d.getYear(); s += '/'; if(d.getMonth() &lt; 9) s += "0" s += (d.getMonth() + 1); s += '/';
		if(d.getDate() &lt; 9) s += "0" s += d.getDate(); return(s); } function getfulldate(obj) {
		var d; d = new Date(obj); return(d.toString()); } function DateAdd(ItemType, objDate,
		ValueToBeAdded) { var DateToWorkOn = new Date(objDate); switch (ItemType) { //date portion
		case 'd': //add days DateToWorkOn.setDate(DateToWorkOn.getDate() + ValueToBeAdded) break;
		case 'm': //add months DateToWorkOn.setMonth(DateToWorkOn.getMonth() + ValueToBeAdded)
		break; case 'y': //add years DateToWorkOn.setYear(DateToWorkOn.getFullYear() +
		ValueToBeAdded) break; //time portion case 'h': //add days
		DateToWorkOn.setHours(DateToWorkOn.getHours() + ValueToBeAdded) break; case 'n': //add
		minutes DateToWorkOn.setMinutes(DateToWorkOn.getMinutes() + ValueToBeAdded) break; case 's':
		//add seconds DateToWorkOn.setSeconds(DateToWorkOn.getSeconds() + ValueToBeAdded) break; }
		return DateToWorkOn.toString(); } function DatePart(ItemType, objDate) { var DateToWorkOn =
		new Date(objDate); var s = ""; switch (ItemType) { //date portion case 'd': //add days
		//if(DateToWorkOn.getDate() &lt; 9) //s += "0" s += DateToWorkOn.getDate() break; case 'm':
		//add months //if(DateToWorkOn.getMonth() &lt; 10) //s += "0" s += DateToWorkOn.getMonth()
		break; case 'y': //add years s += DateToWorkOn.getFullYear() break; //time portion case 'h':
		//add days s += DateToWorkOn.getHours() break; case 'n': //add minutes s +=
		DateToWorkOn.getMinutes() break; case 's': //add seconds s += DateToWorkOn.getSeconds()
		break; } return s; } </msxsl:script>

	<!-- ========================================================================== -->
	<!-- these are 'string arrays' - change for language requirements               -->
	<xsl:variable name="default-week-day-names"
		select="'[1]Monday[2]Tuesday[3]Wednesday[4]Thursday[5]Friday[6]Saturday[7]Sunday[end]'"/>
	<xsl:variable name="default-month-names"
		select="'[01]January[02]February[03]March[04]April[05]May[06]June[07]July[08]August[09]September[10]October[11]November[12]December[end]'"/>
	<xsl:variable name="default-am-pm-names" select="'[0]am[1]pm[end]'"/>
	<!-- ========================================================================== -->

	<!--
==========================================================================
    Template: date-to-julian-day
 Description: Convert a date to julian day
 Parameters:-
    <year> <month> <day>
   or
    <date> (format: yyyymmdd or yyyy-mm-dd)
========================================================================== -->
	<xsl:template name="date-to-julian-day">
		<xsl:param name="year"/>
		<xsl:param name="month"/>
		<xsl:param name="day"/>
		<!-- or -->
		<xsl:param name="date" select="''"/>
		<!-- trim down date -->
		<xsl:variable name="tdate" select="translate($date,'/','')"/>
		<!-- decide which params were passed -->
		<xsl:variable name="yyyy">
			<xsl:choose>
				<xsl:when test="string-length($date) &gt; 0">
					<xsl:value-of select="substring($tdate,1,4)"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$year"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="mm">
			<xsl:choose>
				<xsl:when test="string-length($date) &gt; 0">
					<xsl:value-of select="substring($tdate,5,2)"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$month"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="dd">
			<xsl:choose>
				<xsl:when test="string-length($date) &gt; 0">
					<xsl:value-of select="substring($tdate,7,2)"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$day"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<!-- pre-calcs -->
		<xsl:variable name="j0" select="ceiling(($mm - 14) div 12)"/>
		<xsl:variable name="j1" select="floor((1461 * ($yyyy + 4800 + $j0)) div 4)"/>
		<xsl:variable name="j2" select="floor((367 * ($mm - 2 - (12 * $j0))) div 12)"/>
		<xsl:variable name="j3" select="floor((3 * floor(($yyyy + 4900 + $j0) div 100)) div 4)"/>
		<!-- final calc -->
		<xsl:value-of select="$j1 + $j2 - $j3 + $dd - 32075"/>
	</xsl:template>

	<!--
==========================================================================
    Template: julian-day-to-date
 Description: Convert a julian day to date
 Parameters:-
    <julian-day>
========================================================================== -->
	<xsl:template name="julian-day-to-date">
		<xsl:param name="julian-day" select="number(0)"/>
		<!-- pre-calcs -->
		<xsl:variable name="la" select="$julian-day + 68569"/>
		<xsl:variable name="n" select="floor((4 * $la) div 146097)"/>
		<xsl:variable name="lb" select="$la - floor((146097 * $n + 3) div 4)"/>
		<xsl:variable name="i" select="floor((4000 * ($lb + 1)) div 1461001)"/>
		<xsl:variable name="lc" select="$lb - floor((1461 * $i) div 4) + 31"/>
		<xsl:variable name="j" select="floor((80 * $lc) div 2447)"/>
		<xsl:variable name="day" select="$lc - floor((2447 * $j) div 80)"/>
		<xsl:variable name="ld" select="floor($j div 11)"/>
		<xsl:variable name="month" select="$j + 2 - (12 * $ld)"/>
		<xsl:variable name="year" select="100 * ($n - 49) + $i + $ld"/>
		<!-- pad final result -->
		<xsl:variable name="sday"
			select="concat(substring('00',1,2 - string-length(string($day))),string($day))"/>
		<xsl:variable name="smonth"
			select="concat(substring('00',1,2 - string-length(string($month))),string($month))"/>
		<xsl:variable name="syear"
			select="concat(substring('00',1,4 - string-length(string($year))),string($year))"/>
		<!-- final output -->
		<xsl:value-of select="concat($syear,'/',$smonth,'/',$sday)"/>
	</xsl:template>

	<!--
==========================================================================
    Template: date-diff
 Description: Calculate the difference (in days) between two dates
 Parameters:-
    <year1> <month1> <day1>
   or
    <date1>

   and
    <year2> <month2> <day2>
   or
    <date2>
========================================================================== -->
	<xsl:template name="date-diff">
		<xsl:param name="year1"/>
		<xsl:param name="month1"/>
		<xsl:param name="day1"/>
		<xsl:param name="year2"/>
		<xsl:param name="month2"/>
		<xsl:param name="day2"/>
		<!-- or -->
		<xsl:param name="date1" select="''"/>
		<!-- format: yyyymmdd or yyyy-mm-dd -->
		<xsl:param name="date2" select="''"/>
		<!-- format: yyyymmdd or yyyy-mm-dd -->
		<!-- calc the two julian day numbers -->
		<xsl:variable name="jd1">
			<xsl:call-template name="date-to-julian-day">
				<xsl:with-param name="year" select="$year1"/>
				<xsl:with-param name="month" select="$month1"/>
				<xsl:with-param name="day" select="$day1"/>
				<xsl:with-param name="date" select="$date1"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="jd2">
			<xsl:call-template name="date-to-julian-day">
				<xsl:with-param name="year" select="$year2"/>
				<xsl:with-param name="month" select="$month2"/>
				<xsl:with-param name="day" select="$day2"/>
				<xsl:with-param name="date" select="$date2"/>
			</xsl:call-template>
		</xsl:variable>
		<!-- perform calc -->
		<xsl:value-of select="$jd1 - $jd2"/>
	</xsl:template>

	<!--
==========================================================================
    Template: date-add
 Description: Adds/subtracts a specified number of days to a date
 Parameters:-
    <year> <month> <day>
   or
    <date>

   and
    <add> (+ve or -ve)
========================================================================== -->
	<xsl:template name="date-add">
		<xsl:param name="year"/>
		<xsl:param name="month"/>
		<xsl:param name="day"/>
		<!-- or -->
		<xsl:param name="date" select="''"/>
		<!-- format: yyyymmdd or yyyy-mm-dd -->
		<!-- and add/subtract days -->
		<xsl:param name="add" select="number(0)"/>
		<!-- get the julian day for the date -->
		<xsl:variable name="jd">
			<xsl:call-template name="date-to-julian-day">
				<xsl:with-param name="year" select="$year"/>
				<xsl:with-param name="month" select="$month"/>
				<xsl:with-param name="day" select="$day"/>
				<xsl:with-param name="date" select="$date"/>
			</xsl:call-template>
		</xsl:variable>
		<!-- add/subtract the modifier to the julian day -->
		<xsl:variable name="output-date">
			<xsl:call-template name="julian-day-to-date">
				<xsl:with-param name="julian-day" select="$jd + $add"/>
			</xsl:call-template>
		</xsl:variable>
		<!-- output resultant -->
		<xsl:value-of select="$output-date"/>
	</xsl:template>

	<!--
==========================================================================
    Template: date-time-to-float
 Description: Convert a date/time to a floating point.  The date portion is
              returned as the integer part of the number (as julian day)
              and the time portion is represent as fractional of a day.
              (This number is useful for adding times to dates)
 Parameters:-
    <year> <month> <day> <hour> <minute> <second>
   or
    <datetime>
========================================================================== -->
	<xsl:template name="date-time-to-float">
		<xsl:param name="year"/>
		<xsl:param name="month"/>
		<xsl:param name="day"/>
		<xsl:param name="hour"/>
		<xsl:param name="minute"/>
		<xsl:param name="second"/>
		<!-- or -->
		<xsl:param name="datetime" select="''"/>
		<!-- format: yyyymmddThhmmss or yyyy-mm-ddThh:mm:ss -->
		<!-- trim down date and pad with midnight -->
		<xsl:variable name="tdatetime" select="concat(translate($datetime,'-T:',''),'000000')"/>
		<!-- decide which params were passed -->
		<xsl:variable name="yyyy">
			<xsl:choose>
				<xsl:when test="string-length($datetime) &gt; 0">
					<xsl:value-of select="substring($tdatetime,1,4)"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$year"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="mm">
			<xsl:choose>
				<xsl:when test="string-length($datetime) &gt; 0">
					<xsl:value-of select="substring($tdatetime,5,2)"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$month"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="dd">
			<xsl:choose>
				<xsl:when test="string-length($datetime) &gt; 0">
					<xsl:value-of select="substring($tdatetime,7,2)"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$day"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="hh">
			<xsl:choose>
				<xsl:when test="string-length($datetime) &gt; 0">
					<xsl:value-of select="substring($tdatetime,9,2)"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$hour"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="nn">
			<xsl:choose>
				<xsl:when test="string-length($datetime) &gt; 0">
					<xsl:value-of select="substring($tdatetime,11,2)"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$minute"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="ss">
			<xsl:choose>
				<xsl:when test="string-length($datetime) &gt; 0">
					<xsl:value-of select="substring($tdatetime,13,2)"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$second"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<!-- calculate integer part (date) as julian day -->
		<xsl:variable name="jd">
			<xsl:call-template name="date-to-julian-day">
				<xsl:with-param name="year" select="$yyyy"/>
				<xsl:with-param name="month" select="$mm"/>
				<xsl:with-param name="day" select="$dd"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:value-of
			select="number($jd) + ($hh * (1 div 24)) + ($nn * (1 div 1440)) + ($ss * (1 div 86400))"
		/>
	</xsl:template>

	<!--
==========================================================================
    Template: time-to-float
 Description: Convert a time to a floating point.  The time is returned
              as a fractional part of a day (e.g. 12 noon = 0.5).
              This is useful for adding specified hour differentials
              (such as time zones) to floating point representations of
              date/times.
 Parameters:-
    <hour> <minute> <second>
   or
    <time>
========================================================================== -->
	<xsl:template name="time-to-float">
		<xsl:param name="hour"/>
		<xsl:param name="minute"/>
		<xsl:param name="second"/>
		<!-- or -->
		<xsl:param name="time" select="''"/>
		<!-- format: hhmmss or hh:mm:ss -->
		<!-- trim down time by removing ':' chars -->
		<xsl:variable name="ttime" select="translate($time,':','')"/>
		<!-- decide which params were passed -->
		<xsl:variable name="hh">
			<xsl:choose>
				<xsl:when test="string-length($time) &gt; 0">
					<xsl:value-of select="substring($ttime,1,2)"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$hour"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="nn">
			<xsl:choose>
				<xsl:when test="string-length($time) &gt; 0">
					<xsl:value-of select="concat('0',substring($ttime,3,2))"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="concat('0',$minute)"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="ss">
			<xsl:choose>
				<xsl:when test="string-length($time) &gt; 0">
					<xsl:value-of select="concat('0',substring($ttime,5,2))"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="concat('0',$second)"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<!-- final resultant -->
		<xsl:value-of select="($hh * (1 div 24)) + ($nn * (1 div 1440)) + ($ss * (1 div 86400))"/>
	</xsl:template>

	<!-- 
==========================================================================
    Template: float-to-date-time
 Description: Convert a floating point value representing a date/time to
              a date/time string.
 Parameters:-
    <value>  the value to be converted
    <round-seconds>  if true then the seconds are not quoted on the output
                     and, if the seconds are 59 then hour/minute is rounded
                     (this is useful because some processors have limited
                      floating point precision to cope with the seconds)
========================================================================== -->
	<xsl:template name="float-to-date-time">
		<xsl:param name="value" select="number(0)"/>
		<xsl:param name="round-seconds" select="false()"/>
		<xsl:variable name="date">
			<xsl:call-template name="julian-day-to-date">
				<xsl:with-param name="julian-day" select="floor($value)"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="t1" select="$value - floor($value)"/>
		<xsl:variable name="h" select="floor($t1 div (1 div 24))"/>
		<xsl:variable name="t2" select="$t1 - ($h * (1 div 24))"/>
		<xsl:variable name="m" select="floor($t2 div (1 div 1440))"/>
		<xsl:variable name="t3" select="$t2 - ($m * (1 div 1440))"/>
		<xsl:choose>
			<xsl:when test="$round-seconds">
				<xsl:variable name="s" select="$t3 div (1 div 86400)"/>
				<xsl:variable name="h2">
					<xsl:choose>
						<xsl:when test="($s &gt;= 59) and ($m = 59)">
							<xsl:value-of select="$h + 1"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="$h"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<xsl:variable name="m2">
					<xsl:choose>
						<xsl:when test="($s &gt;= 59) and ($m = 59)">0</xsl:when>
						<xsl:when test="($s &gt;= 59)">
							<xsl:value-of select="$m + 1"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="$m"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<!-- pad final time result -->
				<xsl:variable name="hh"
					select="concat(substring('00',1,2 - string-length(string($h2))),string($h2))"/>
				<xsl:variable name="mm"
					select="concat(substring('00',1,2 - string-length(string($m2))),string($m2))"/>
				<!-- final output resultant -->
				<xsl:value-of select="concat($date,'T',$hh,':',$mm)"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:variable name="s" select="floor($t3 div (1 div 86400))"/>
				<!-- pad final time result -->
				<xsl:variable name="hh"
					select="concat(substring('00',1,2 - string-length(string($h))),string($h))"/>
				<xsl:variable name="mm"
					select="concat(substring('00',1,2 - string-length(string($m))),string($m))"/>
				<xsl:variable name="ss"
					select="concat(substring('00',1,2 - string-length(string($s))),string($s))"/>
				<!-- final output resultant -->
				<xsl:value-of select="concat($date,'T',$hh,':',$mm,':',$ss)"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<!--
==========================================================================
    Template: week-number
 Description: Calculates the week number of a date.
              Week numbers are calculated according to ISO8601 - where week
              number 1 is the week that contains the 4th Jan.
              A week, according to ISO8601, starts on a Monday.
 Parameters:-
    <year> <month> <day>
   or
    <date>
   or
    <julian-day>
========================================================================== -->
	<xsl:template name="week-number">
		<xsl:param name="year"/>
		<xsl:param name="month"/>
		<xsl:param name="day"/>
		<!-- or -->
		<xsl:param name="date" select="''"/>
		<!-- format: yyyymmdd or yyyy-mm-dd -->
		<!-- or -->
		<xsl:param name="julian-day" select="''"/>
		<!-- trim down date -->
		<xsl:variable name="tdate" select="translate($date,'/','')"/>
		<!-- decide which params were passed -->
		<xsl:variable name="yyyy">
			<xsl:choose>
				<xsl:when test="string-length($date) &gt; 0">
					<xsl:value-of select="substring($tdate,1,4)"/>
				</xsl:when>
				<xsl:when test="string-length($julian-day) &gt; 0">
					<xsl:variable name="jdate">
						<xsl:call-template name="julian-day-to-date">
							<xsl:with-param name="julian-day" select="$julian-day"/>
						</xsl:call-template>
					</xsl:variable>
					<xsl:value-of select="substring($jdate,1,4)"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$year"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<!-- get the julian day number -->
		<xsl:variable name="jd">
			<xsl:choose>
				<xsl:when test="string-length($julian-day) &gt; 0">
					<xsl:value-of select="$julian-day"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="date-to-julian-day">
						<xsl:with-param name="year" select="$year"/>
						<xsl:with-param name="month" select="$month"/>
						<xsl:with-param name="day" select="$day"/>
						<xsl:with-param name="date" select="$date"/>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<!-- get the julian day number for the first working day of next year -->
		<xsl:variable name="fyjd">
			<xsl:call-template name="first-day-of-year">
				<xsl:with-param name="year" select="$yyyy+1"/>
				<xsl:with-param name="as-julian-day" select="true()"/>
			</xsl:call-template>
		</xsl:variable>
		<!-- decide which the 'working' year for this date is -->
		<xsl:variable name="start-jd">
			<xsl:choose>
				<xsl:when test="$jd &gt;= $fyjd">
					<xsl:value-of select="$fyjd"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="date-to-julian-day">
						<xsl:with-param name="date">
							<xsl:call-template name="first-day-of-year">
								<xsl:with-param name="year" select="$yyyy"/>
							</xsl:call-template>
						</xsl:with-param>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<!-- final calc output -->
		<xsl:value-of select="floor(($jd - $start-jd) div 7) + 1"/>
	</xsl:template>

	<!--
==========================================================================
    Template: week-number-to-date
 Description: Calculates the date of the Monday of the given week number in
              the specified year.
              Week numbers are calculated according to ISO8601 - where week
              number 1 is the week that contains the 4th Jan.
              A week, according to ISO8601, starts on a Monday.
 Parameters:-
    <week> <year>
    [<as-julian-day>]
========================================================================== -->
	<xsl:template name="week-number-to-date">
		<xsl:param name="week" select="number(1)"/>
		<xsl:param name="year" select="number(1)"/>
		<!-- return date as julian day -->
		<xsl:param name="as-julian-day" select="false()"/>
		<!-- calc first working day of year -->
		<xsl:variable name="fwdy">
			<xsl:call-template name="first-day-of-year">
				<xsl:with-param name="year" select="$year"/>
				<xsl:with-param name="as-julian-day" select="true()"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="wntd" select="$fwdy + (($week - 1) * 7)"/>
		<xsl:choose>
			<xsl:when test="$as-julian-day">
				<xsl:value-of select="$wntd"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="julian-day-to-date">
					<xsl:with-param name="julian-day" select="$wntd"/>
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<!--
==========================================================================
    Template: working-year
 Description: Calculates the working year of a given date.
              A date may actually appear as a working day of the previous
              year - as specified by the week calculations according to
              ISO8601 (where week number 1 begins the week containing the
              4th Jan).
 Parameters:-
    <year> <month> <day>
   or
    <date>
   or
    <julian-day>
========================================================================== -->
	<xsl:template name="working-year">
		<xsl:param name="year"/>
		<xsl:param name="month"/>
		<xsl:param name="day"/>
		<!-- or -->
		<xsl:param name="date" select="''"/>
		<!-- format: yyyymmdd or yyyy-mm-dd -->
		<!-- or -->
		<xsl:param name="julian-day" select="''"/>
		<!-- trim down date -->
		<xsl:variable name="tdate" select="translate($date,'/','')"/>
		<!-- decide which params were passed -->
		<xsl:variable name="yyyy">
			<xsl:choose>
				<xsl:when test="string-length($date) &gt; 0">
					<xsl:value-of select="substring($tdate,1,4)"/>
				</xsl:when>
				<xsl:when test="string-length($julian-day) &gt; 0">
					<xsl:variable name="jdate">
						<xsl:call-template name="julian-day-to-date">
							<xsl:with-param name="julian-day" select="$julian-day"/>
						</xsl:call-template>
					</xsl:variable>
					<xsl:value-of select="substring($jdate,1,4)"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$year"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<!-- get the julian day number -->
		<xsl:variable name="jd">
			<xsl:choose>
				<xsl:when test="string-length($julian-day) &gt; 0">
					<xsl:value-of select="$julian-day"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="date-to-julian-day">
						<xsl:with-param name="year" select="$year"/>
						<xsl:with-param name="month" select="$month"/>
						<xsl:with-param name="day" select="$day"/>
						<xsl:with-param name="date" select="$date"/>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<!-- get the julian day number for the first working day of next year -->
		<xsl:variable name="fyjd">
			<xsl:call-template name="first-day-of-year">
				<xsl:with-param name="year" select="$yyyy+1"/>
				<xsl:with-param name="as-julian-day" select="true()"/>
			</xsl:call-template>
		</xsl:variable>
		<!-- decide which the 'working' year for this date is -->
		<xsl:choose>
			<xsl:when test="$jd &gt;= $fyjd">
				<xsl:value-of select="$yyyy+1"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$yyyy"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<!--
==========================================================================
    Template: weeks-in-year
 Description: Calculates the number of weeks in a year according to the
              ISO8601 standard for weeks.
 Parameters:-
    <year>
========================================================================== -->
	<xsl:template name="weeks-in-year">
		<xsl:param name="year" select="number(0)"/>
		<xsl:variable name="syear"
			select="concat(substring('0000',1,4 - string-length($year)),$year)"/>
		<!-- last week in year is always the week that contains 28th December -->
		<xsl:call-template name="week-number">
			<xsl:with-param name="date" select="concat($syear,'1228')"/>
		</xsl:call-template>
	</xsl:template>

	<!--
==========================================================================
    Template: first-day-of-year
 Description: Calculates the first working day of the year (Monday)
              according to ISO8601 where week 1 of a year is the week that
              contains the 4th Jan.
 Parameters:-
    <year>
    [<as-julian-day>]
========================================================================== -->
	<xsl:template name="first-day-of-year">
		<xsl:param name="year"/>
		<xsl:param name="as-julian-day" select="false()"/>
		<xsl:variable name="syear"
			select="concat(substring('0000',1,4 - string-length($year)),$year)"/>
		<!-- week 1 is the week containing 4th Jan -->
		<xsl:variable name="jan4-jd">
			<xsl:call-template name="date-to-julian-day">
				<xsl:with-param name="date" select="concat($syear,'0104')"/>
			</xsl:call-template>
		</xsl:variable>
		<!-- get the week day for the 4th Jan -->
		<xsl:variable name="jan4-wd">
			<xsl:call-template name="day-of-week">
				<xsl:with-param name="date" select="concat($syear,'0104')"/>
			</xsl:call-template>
		</xsl:variable>
		<!-- first day is the prev monday -->
		<xsl:choose>
			<xsl:when test="$as-julian-day">
				<xsl:value-of select="$jan4-jd - ($jan4-wd - 1)"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="julian-day-to-date">
					<xsl:with-param name="julian-day" select="$jan4-jd - ($jan4-wd - 1)"/>
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<!--
==========================================================================
    Template: day-of-week
 Description: Calculates the day of the week for a date - where the first
              day of the week is Monday (1) and the last day of the week is
              is Sunday (7) - according to ISO8601.
 Parameters:-
    <year> <month> <day>
   or
    <date>
   or
    <julian-day>
========================================================================== -->
	<xsl:template name="day-of-week">
		<xsl:param name="year"/>
		<xsl:param name="month"/>
		<xsl:param name="day"/>
		<!-- or -->
		<xsl:param name="date" select="''"/>
		<!-- format: yyyymmdd or yyyy-mm-dd -->
		<!-- or -->
		<xsl:param name="julian-day" select="''"/>
		<!-- get julian day -->
		<xsl:variable name="jd">
			<xsl:choose>
				<xsl:when test="string-length($julian-day) &gt; 0">
					<xsl:value-of select="$julian-day"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="date-to-julian-day">
						<xsl:with-param name="year" select="$year"/>
						<xsl:with-param name="month" select="$month"/>
						<xsl:with-param name="day" select="$day"/>
						<xsl:with-param name="date" select="$date"/>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<!-- pre-calcs -->
		<xsl:variable name="dw0" select="$jd mod 10227"/>
		<xsl:value-of select="($dw0 mod 7) + 1"/>
	</xsl:template>

	<!--
==========================================================================
    Template: named-day-of-week
 Description: Calculates the day of the week for a date - where the first
              day of the week is Monday (1) and the last day of the week is
              is Sunday (7) - according to ISO8601.
              The day of week is returned as its name.
 Parameters:-
    <year> <month> <day>
   or
    <date>
   or
    <julian-day>
   optional override parameter:-
   [<week-day-names>]
========================================================================== -->
	<xsl:template name="named-day-of-week">
		<xsl:param name="year"/>
		<xsl:param name="month"/>
		<xsl:param name="day"/>
		<!-- or -->
		<xsl:param name="date" select="''"/>
		<!-- format: yyyymmdd or yyyy-mm-dd -->
		<!-- or -->
		<xsl:param name="julian-day" select="''"/>
		<!-- override week day names parameter -->
		<xsl:param name="week-day-names" select="$default-week-day-names"/>
		<!-- get numeric day of week -->
		<xsl:variable name="dwn">
			<xsl:text>[</xsl:text>
			<xsl:call-template name="day-of-week">
				<xsl:with-param name="year" select="$year"/>
				<xsl:with-param name="month" select="$month"/>
				<xsl:with-param name="day" select="$day"/>
				<xsl:with-param name="date" select="$date"/>
				<xsl:with-param name="julian-day" select="$julian-day"/>
			</xsl:call-template>
			<xsl:text>]</xsl:text>
		</xsl:variable>
		<xsl:value-of
			select="substring-before(substring($week-day-names,string-length(substring-before($week-day-names,$dwn)) + 4),'[')"
		/>
	</xsl:template>

	<!--
==========================================================================
    Template: format-date-time
 Description: Formats a given date/time according to a format string.
 Parameters:-
   <format-string>

    <year> <month> <day> <hour> <minute> <second>
   or
    <datetime>
   or
    <julian-day>
   optional override parameters:-
   [<week-day-names>]
   [<month-names>]
   [<am-pm-names>]

 Format string tokens:-
   yyyy    : Year (4-digit)
   yy      : Year (2-digit)
   mmmm    : Month name (full)
   mmm     : Month name (abbreviated to 3 chars)
   mm      : Month (padded with zero to two digits)
   m       : Month (1 ro 2 digits)
   dd      : Day (padded with zero to teo digits)
   d       : Day (1 or 2 digits)
   th      : nth day modifier (e.g. st, nd, rd, th)
   dowwww  : Day of week (full - e.g Monday, Tuesday etc.)
   dowww   : Day of week (abbreviated to 3 chars - e.g. Mon, Tue etc.)
   dow     : Day of week (numeric: 1=Monday)
   wyyyy   : Working year (4-digit)
   wyy     : Working year (2-digit)
   wnn     : Week number (padded with zero to two digits)
   wn      : Week number (1 or 2 digits)
   hm      : Hour (reduced to 12-hour clock - 1 or 2 digits)
   hh      : Hour (24-hour clock - padded with zero to two digits)
   h       : Hour (1 or 2 digits)
   nn      : Minute (padded with zero to two digits)
   n       : Minute (1 or 2 digits)
   ss      : Second (padded with zero to two digits)
   s       : Second (1 or 2 digits)
   apm     : am/pm marker
   'x...x' : Literal string
   "x...x" : Literal string
========================================================================== -->
	<xsl:template name="format-date-time">
		<!-- required format -->
		<xsl:param name="format-string">yyyy-mm-dd&apos;T&apos;hh:nn:ss</xsl:param>
		<!-- passed date/time -->
		<xsl:param name="year"/>
		<xsl:param name="month"/>
		<xsl:param name="day"/>
		<xsl:param name="hour"/>
		<xsl:param name="minute"/>
		<xsl:param name="second"/>
		<!-- or -->
		<xsl:param name="datetime" select="''"/>
		<!-- format: yyyymmddThhmmss or yyyy-mm-ddThh:mm:ss -->
		<!-- or -->
		<xsl:param name="julian-day" select="''"/>
		<!-- this can be float type to include times -->
		<!-- default week day, month and am/pm names overrides -->
		<xsl:param name="week-day-names" select="$default-week-day-names"/>
		<xsl:param name="month-names" select="$default-month-names"/>
		<xsl:param name="am-pm-names" select="$default-am-pm-names"/>
		<!-- convert date passed to common format -->
		<xsl:variable name="use-datetime">
			<xsl:choose>
				<xsl:when test="string-length($datetime) &gt; 0">
					<xsl:variable name="tdate" select="translate($datetime,'-:T','')"/>
					<xsl:value-of
						select="concat($tdate,substring('00000000000000',1,14 - string-length($tdate)))"
					/>
				</xsl:when>
				<xsl:when test="string-length($julian-day) &gt; 0">
					<xsl:variable name="tdate">
						<xsl:call-template name="float-to-date-time">
							<xsl:with-param name="value" select="$julian-day"/>
						</xsl:call-template>
					</xsl:variable>
					<xsl:value-of select="translate($tdate,'-:T','')"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of
						select="concat(substring('0000',1,4 - string-length($year)),$year)"/>
					<xsl:value-of
						select="concat(substring('00',1,2 - string-length($month)),$month)"/>
					<xsl:value-of select="concat(substring('00',1,2 - string-length($day)),$day)"/>
					<xsl:value-of select="concat(substring('00',1,2 - string-length($hour)),$hour)"/>
					<xsl:value-of
						select="concat(substring('00',1,2 - string-length($minute)),$minute)"/>
					<xsl:value-of
						select="concat(substring('00',1,2 - string-length($second)),$second)"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:call-template name="format-date-time-tokenizer">
			<xsl:with-param name="fmt" select="$format-string"/>
			<xsl:with-param name="datetime" select="$use-datetime"/>
			<xsl:with-param name="week-day-names" select="$week-day-names"/>
			<xsl:with-param name="month-names" select="$month-names"/>
			<xsl:with-param name="am-pm-names" select="$am-pm-names"/>
		</xsl:call-template>
	</xsl:template>
	<xsl:template name="format-date-time-tokenizer">
		<xsl:param name="fmt">yyyy-mm-dd&apos;T&apos;hh:nn:ss</xsl:param>
		<xsl:param name="datetime"/>
		<xsl:param name="week-day-names" select="$default-week-day-names"/>
		<xsl:param name="month-names" select="$default-month-names"/>
		<xsl:param name="am-pm-names" select="$default-am-pm-names"/>
		<xsl:if test="string-length($fmt) &gt; 0">
			<xsl:variable name="token">
				<xsl:choose>
					<xsl:when test="substring($fmt,1,4) = 'yyyy'">
						<xsl:text>yyyy</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,2) = 'yy'">
						<xsl:text>yy</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,4) = 'mmmm'">
						<xsl:text>mmmm</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,3) = 'mmm'">
						<xsl:text>mmm</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,2) = 'mm'">
						<xsl:text>mm</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,1) = 'm'">
						<xsl:text>m</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,2) = 'th'">
						<xsl:text>th</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,6) = 'dowwww'">
						<xsl:text>dowwww</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,5) = 'dowww'">
						<xsl:text>dowww</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,3) = 'dow'">
						<xsl:text>dow</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,2) = 'dd'">
						<xsl:text>dd</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,1) = 'd'">
						<xsl:text>d</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,5) = 'wyyyy'">
						<xsl:text>wyyyy</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,3) = 'wyy'">
						<xsl:text>wyy</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,3) = 'wnn'">
						<xsl:text>wnn</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,2) = 'wn'">
						<xsl:text>wn</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,2) = 'hm'">
						<xsl:text>hm</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,2) = 'hh'">
						<xsl:text>hh</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,1) = 'h'">
						<xsl:text>h</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,2) = 'nn'">
						<xsl:text>nn</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,1) = 'n'">
						<xsl:text>n</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,2) = 'ss'">
						<xsl:text>ss</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,1) = 's'">
						<xsl:text>s</xsl:text>
					</xsl:when>
					<xsl:when test="substring($fmt,1,3) = 'apm'">
						<xsl:text>apm</xsl:text>
					</xsl:when>
					<xsl:when test='string-length(translate(substring($fmt,1,1),"&apos;","")) = 0'>
						<xsl:variable name="rn"
							select='string-length(substring-before(substring($fmt,2),"&apos;"))'/>
						<xsl:value-of select="substring($fmt,1,$rn+2)"/>
					</xsl:when>
					<xsl:when test="string-length(translate(substring($fmt,1,1),'&quot;','')) = 0">
						<xsl:variable name="rn"
							select="string-length(substring-before(substring($fmt,2),'&quot;'))"/>
						<xsl:value-of select="substring($fmt,1,$rn+2)"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="substring($fmt,1,1)"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:variable>
			<!-- handle the token -->
			<xsl:call-template name="format-date-time-tokens">
				<xsl:with-param name="token" select="$token"/>
				<xsl:with-param name="datetime" select="$datetime"/>
				<xsl:with-param name="week-day-names" select="$week-day-names"/>
				<xsl:with-param name="month-names" select="$month-names"/>
				<xsl:with-param name="am-pm-names" select="$am-pm-names"/>
			</xsl:call-template>
			<!-- recurse into self to handle rest of format string -->
			<xsl:call-template name="format-date-time-tokenizer">
				<xsl:with-param name="fmt" select="substring($fmt,string-length($token) + 1)"/>
				<xsl:with-param name="datetime" select="$datetime"/>
				<xsl:with-param name="week-day-names" select="$week-day-names"/>
				<xsl:with-param name="month-names" select="$month-names"/>
				<xsl:with-param name="am-pm-names" select="$am-pm-names"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
	<xsl:template name="format-date-time-tokens">
		<xsl:param name="token"/>
		<xsl:param name="datetime"/>
		<xsl:param name="week-day-names"/>
		<xsl:param name="month-names"/>
		<xsl:param name="am-pm-names"/>
		<xsl:choose>
			<xsl:when test="$token = 'yyyy'">
				<xsl:value-of select="substring($datetime,1,4)"/>
			</xsl:when>
			<xsl:when test="$token = 'yy'">
				<xsl:value-of select="substring($datetime,3,2)"/>
			</xsl:when>
			<xsl:when test="$token = 'mmmm'">
				<xsl:variable name="mn" select="concat('[',substring($datetime,5,2),']')"/>
				<xsl:value-of
					select="substring-before(substring($month-names,string-length(substring-before($month-names,$mn)) + 5),'[')"
				/>
			</xsl:when>
			<xsl:when test="$token = 'mmm'">
				<xsl:variable name="mn" select="concat('[',substring($datetime,5,2),']')"/>
				<xsl:value-of
					select="substring(substring-before(substring($month-names,string-length(substring-before($month-names,$mn)) + 5),'['),1,3)"
				/>
			</xsl:when>
			<xsl:when test="$token = 'mm'">
				<xsl:value-of select="substring($datetime,5,2)"/>
			</xsl:when>
			<xsl:when test="$token = 'm'">
				<xsl:value-of select="number(substring($datetime,5,2))"/>
			</xsl:when>
			<xsl:when test="$token = 'th'">
				<xsl:choose>
					<xsl:when
						test="substring($datetime,8,1) = '0' or substring($datetime,7,1) = '1'">
						<xsl:text>th</xsl:text>
					</xsl:when>
					<xsl:otherwise>
						<xsl:choose>
							<xsl:when test="substring($datetime,8,1) = '1'">
								<xsl:text>st</xsl:text>
							</xsl:when>
							<xsl:when test="substring($datetime,8,1) = '2'">
								<xsl:text>nd</xsl:text>
							</xsl:when>
							<xsl:when test="substring($datetime,8,1) = '3'">
								<xsl:text>rd</xsl:text>
							</xsl:when>
							<xsl:otherwise>
								<xsl:text>th</xsl:text>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:when test="$token = 'dd'">
				<xsl:value-of select="substring($datetime,7,2)"/>
			</xsl:when>
			<xsl:when test="$token = 'd'">
				<xsl:value-of select="number(substring($datetime,7,2))"/>
			</xsl:when>
			<xsl:when test="$token = 'dowwww'">
				<xsl:call-template name="named-day-of-week">
					<xsl:with-param name="date" select="substring($datetime,1,8)"/>
					<xsl:with-param name="week-day-names" select="$week-day-names"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:when test="$token = 'dowww'">
				<xsl:variable name="dow">
					<xsl:call-template name="named-day-of-week">
						<xsl:with-param name="date" select="substring($datetime,1,8)"/>
						<xsl:with-param name="week-day-names" select="$week-day-names"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:value-of select="substring($dow,1,3)"/>
			</xsl:when>
			<xsl:when test="$token = 'dow'">
				<xsl:call-template name="day-of-week">
					<xsl:with-param name="date" select="substring($datetime,1,8)"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:when test="$token = 'wyyyy'">
				<xsl:call-template name="working-year">
					<xsl:with-param name="date" select="substring($datetime,1,8)"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:when test="$token = 'wyy'">
				<xsl:variable name="wyy">
					<xsl:call-template name="working-year">
						<xsl:with-param name="date" select="substring($datetime,1,8)"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:value-of select="substring($wyy,3,2)"/>
			</xsl:when>
			<xsl:when test="$token = 'wnn'">
				<xsl:variable name="wn">
					<xsl:call-template name="week-number">
						<xsl:with-param name="date" select="substring($datetime,1,8)"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:value-of select="concat(substring('00',1,2 - string-length($wn)),$wn)"/>
			</xsl:when>
			<xsl:when test="$token = 'wn'">
				<xsl:call-template name="week-number">
					<xsl:with-param name="date" select="substring($datetime,1,8)"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:when test="$token = 'hm'">
				<xsl:variable name="hm" select="number(substring($datetime,9,2))"/>
				<xsl:choose>
					<xsl:when test="$hm &gt; 12">
						<xsl:value-of select="$hm - 12"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="$hm"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:when test="$token = 'hh'">
				<xsl:value-of select="substring($datetime,9,2)"/>
			</xsl:when>
			<xsl:when test="$token = 'h'">
				<xsl:value-of select="number(substring($datetime,9,2))"/>
			</xsl:when>
			<xsl:when test="$token = 'nn'">
				<xsl:value-of select="substring($datetime,11,2)"/>
			</xsl:when>
			<xsl:when test="$token = 'n'">
				<xsl:value-of select="number(substring($datetime,11,2))"/>
			</xsl:when>
			<xsl:when test="$token = 'ss'">
				<xsl:value-of select="substring($datetime,13,2)"/>
			</xsl:when>
			<xsl:when test="$token = 's'">
				<xsl:value-of select="number(substring($datetime,13,2))"/>
			</xsl:when>
			<xsl:when test="$token = 'apm'">
				<xsl:variable name="apm"
					select="concat('[',number(substring($datetime,9,2)) mod 12,']')"/>
				<xsl:value-of
					select="substring-before(substring($am-pm-names,string-length(substring-before($am-pm-names,$apm)) + 4),'[')"
				/>
			</xsl:when>
			<xsl:when test='string-length(translate(substring($token,1,1),"&apos;","")) = 0'>
				<xsl:value-of select="substring($token,2,string-length($token) - 2)"/>
			</xsl:when>
			<xsl:when test="string-length(translate(substring($token,1,1),'&quot;','')) = 0">
				<xsl:value-of select="substring($token,2,string-length($token) - 2)"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$token"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<!--
==========================================================================
    Template: local-to-UTC
 Description: Converts a local date/time (in the format yyyymmddThhmmssZ+-hhmm
              or yyyy-mm-ddThh:mm:ssZ+-hh:mm) to a UTC date/time.
 Parameters:-
   <datetime> the local date/time to be converted.
-->
	<xsl:template name="local-to-UTC">
		<xsl:param name="datetime"/>
		<!-- get the time zone offset part of the date/time -->
		<xsl:variable name="local-offset">
			<xsl:choose>
				<xsl:when test="contains($datetime,'Z')">
					<!-- get the local offset portion (and strip out '+' and ':' chars) -->
					<xsl:variable name="offset-portion"
						select="translate(substring-after($datetime,'Z'),'+:','')"/>
					<xsl:choose>
						<xsl:when test="string-length($offset-portion) = 0">0</xsl:when>
						<xsl:otherwise>
							<!-- convert hours/mins to a numeric value -->
							<xsl:variable name="offset-val">
								<xsl:call-template name="time-to-float">
									<xsl:with-param name="time"
										select="translate($offset-portion,'/','')"/>
								</xsl:call-template>
							</xsl:variable>
							<!-- adjust value + or - -->
							<xsl:choose>
								<xsl:when test="substring($offset-portion,1,1) = '/'">
									<xsl:value-of select="$offset-val"/>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="0 - $offset-val"/>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:when>
				<xsl:otherwise>0</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:choose>
			<xsl:when test="$local-offset != 0">
				<xsl:variable name="dt2"
					select="translate(substring-before($datetime,'Z'),'-T:','')"/>
				<xsl:variable name="date-value">
					<xsl:call-template name="date-time-to-float">
						<xsl:with-param name="datetime" select="$dt2"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:variable name="output-datetime">
					<xsl:call-template name="float-to-date-time">
						<xsl:with-param name="value" select="$date-value + $local-offset"/>
						<xsl:with-param name="round-seconds" select="true()"/>
					</xsl:call-template>
				</xsl:variable>
				<!-- if seconds specified on the original time then add these back on -->
				<xsl:choose>
					<xsl:when test="string-length($dt2) &gt; 12">
						<xsl:value-of select="concat($output-datetime,':',substring($dt2,13,2))"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="$output-datetime"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="concat($datetime,'Z')"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<!--
==========================================================================
    Template: UTC-to-local
 Description: Converts a UTC date/time (in the format yyyymmddThhmmss
              or yyyy-mm-ddThh:mm:ss) to a local date/time.
 Parameters:-
   <datetime>     the UTC date/time to be converted.
   <local-offset> the local time offset (in the format +hh:mm or
                  -hh:mm)
-->
	<xsl:template name="UTC-to-local">
		<xsl:param name="datetime"/>
		<xsl:param name="local-offset" select="'0000'"/>
		<xsl:variable name="raw-offset"
			select="concat(substring('0000',1,4 - string-length(translate($local-offset,'+-:',''))),translate($local-offset,'+-:',''))"/>
		<!-- calc the offset as a value -->
		<xsl:variable name="offset">
			<xsl:choose>
				<xsl:when test="$raw-offset = '0000'">0</xsl:when>
				<xsl:otherwise>
					<!-- convert hours/mins to a numeric value -->
					<xsl:variable name="offset-val">
						<xsl:call-template name="time-to-float">
							<xsl:with-param name="time" select="$raw-offset"/>
						</xsl:call-template>
					</xsl:variable>
					<!-- adjust value + or - -->
					<xsl:choose>
						<xsl:when test="contains($local-offset,'-')">
							<xsl:value-of select="0 - $offset-val"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="$offset-val"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:choose>
			<xsl:when test="$offset != 0">
				<xsl:variable name="dt2" select="translate($datetime,'-T:','')"/>
				<xsl:variable name="date-value">
					<xsl:call-template name="date-time-to-float">
						<xsl:with-param name="datetime" select="$dt2"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:variable name="output-datetime">
					<xsl:call-template name="float-to-date-time">
						<xsl:with-param name="value" select="$date-value + $offset"/>
						<xsl:with-param name="round-seconds" select="true()"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:variable name="plusminus">
					<xsl:choose>
						<xsl:when test="contains($local-offset,'-')">-</xsl:when>
						<xsl:otherwise>+</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<!-- if seconds specified on the original time then add these back on -->
				<xsl:choose>
					<xsl:when test="string-length($dt2) &gt; 12">
						<xsl:value-of
							select="concat($output-datetime,':',substring($dt2,13,2),'Z',$plusminus,substring($raw-offset,1,2),':',substring($raw-offset,3,2))"
						/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of
							select="concat($output-datetime,'Z',$plusminus,substring($raw-offset,1,2),':',substring($raw-offset,3,2))"
						/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="concat($datetime,'Z')"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<!--
==========================================================================
    Template: local-to-local
 Description: Converts one local date/time (in the format yyyymmddThhmmssZ+-hhmm
              or yyyy-mm-ddThh:mm:ssZ+-hh:mm) to another local date/time based
              upon a given new local time offset.
 Parameters:-
   <datetime>     the local date/time to be converted.
   <local-offset> the new local time offset (in the format +hh:mm or
                  -hh:mm)
-->
	<xsl:template name="local-to-local">
		<xsl:param name="datetime"/>
		<xsl:param name="local-offset" select="'0000'"/>
		<!-- get the time zone offset part of the date/time -->
		<xsl:variable name="offset">
			<xsl:choose>
				<xsl:when test="contains($datetime,'Z')">
					<!-- get the local offset portion (and strip out '+' and ':' chars) -->
					<xsl:variable name="offset-portion"
						select="translate(substring-after($datetime,'Z'),'+:','')"/>
					<xsl:choose>
						<xsl:when test="string-length($offset-portion) = 0">0</xsl:when>
						<xsl:otherwise>
							<!-- convert hours/mins to a numeric value -->
							<xsl:variable name="offset-val">
								<xsl:call-template name="time-to-float">
									<xsl:with-param name="time"
										select="translate($offset-portion,'-','')"/>
								</xsl:call-template>
							</xsl:variable>
							<!-- adjust value + or - -->
							<xsl:choose>
								<xsl:when test="substring($offset-portion,1,1) = '-'">
									<xsl:value-of select="0 - $offset-val"/>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="$offset-val"/>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:when>
				<xsl:otherwise>0</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<!-- calc the new offset -->
		<xsl:variable name="raw-offset"
			select="concat(substring('0000',1,4 - string-length(translate($local-offset,'+-:',''))),translate($local-offset,'+-:',''))"/>
		<xsl:variable name="new-offset">
			<xsl:choose>
				<xsl:when test="$raw-offset = '0000'">0</xsl:when>
				<xsl:otherwise>
					<!-- convert hours/mins to a numeric value -->
					<xsl:variable name="offset-val">
						<xsl:call-template name="time-to-float">
							<xsl:with-param name="time" select="$raw-offset"/>
						</xsl:call-template>
					</xsl:variable>
					<!-- adjust value + or - -->
					<xsl:choose>
						<xsl:when test="contains($local-offset,'-')">
							<xsl:value-of select="0 - $offset-val"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="$offset-val"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<!-- perform the final time differential -->
		<xsl:choose>
			<xsl:when test="($offset != 0) and ($new-offset != 0)">
				<xsl:variable name="diff-offset" select="$new-offset - $offset"/>
				<xsl:variable name="dt2"
					select="translate(substring-before($datetime,'Z'),'-T:','')"/>
				<xsl:variable name="date-value">
					<xsl:call-template name="date-time-to-float">
						<xsl:with-param name="datetime" select="$dt2"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:variable name="output-datetime">
					<xsl:call-template name="float-to-date-time">
						<xsl:with-param name="value" select="$date-value + $diff-offset"/>
						<xsl:with-param name="round-seconds" select="true()"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:variable name="plusminus">
					<xsl:choose>
						<xsl:when test="contains($local-offset,'-')">-</xsl:when>
						<xsl:otherwise>+</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<!-- if seconds specified on the original time then add these back on -->
				<xsl:choose>
					<xsl:when test="string-length($dt2) &gt; 12">
						<xsl:value-of
							select="concat($output-datetime,':',substring($dt2,13,2),'Z',$plusminus,substring($raw-offset,1,2),':',substring($raw-offset,3,2))"
						/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of
							select="concat($output-datetime,'Z',$plusminus,substring($raw-offset,1,2),':',substring($raw-offset,3,2))"
						/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="concat($datetime,'Z')"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

</xsl:stylesheet>

Open in new window

0
 

Author Comment

by:avivap
Comment Utility
Hi,
Thanks for getting back with me so quickly.
This script was actually a working script, until I attempted my modifications...
Regardless - what do you use to debug?  I'd love to know!
I'm new to this project and so I'm not really sure how to go about getting a hold of the XML...
What usually causes a screen to be totally blank vs "Error Loading XSL Document"?
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 250 total points
Comment Utility
If you look at it in a browser and you don't catch the errors, the screen will likely blank out
There also are two steps in loading an XSLT
The first is loading it as an XML, if there are wellformedness errors in the XSLT (as an XML file) or the file is not found, you will get errors on the loading
If there are runtime errors because the XSLT itself is not valid in terms of an XSLT stylesheet, you might not spot them

I use oxygen (www.oxygenxml.com) No doubt the best IDE for XML development
0
 

Author Comment

by:avivap
Comment Utility
Very helpful!
Thanks so much, and I learned a lot.
0
 
LVL 35

Expert Comment

by:mccarl
Comment Utility
@Geert,

My mistake, yes I unintentionally left that leading // in from the authors original line. It wasn't supposed to be there.

@avivap,

Considering the bulk of the solution that you have used came from my post, I am wondering why multiple answers weren't awarded?
0
 

Author Comment

by:avivap
Comment Utility
HI,
I actually thought that I DID specify multiple answers.
What did I do wrong?
0
 
LVL 35

Expert Comment

by:mccarl
Comment Utility
What did I do wrong?
I'm not sure :)

You can click the "Request Attention" link that's just under your original question and the admins can help.
0
 
LVL 35

Expert Comment

by:mccarl
Comment Utility
@avivap,

Thanks for accepting! :)
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Using YubiKey with REST API application 2 77
Change to event 1 72
Image decoding from Camera 3 42
ASP Focus problem 3 26
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to dynamically set the form action using jQuery.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now