Archive for March, 2010

Quote of the day from the Content Management System Team Leader, wishing for dynamic content delivery to replace statically produced decoupled web pages. I couldn’t help but laugh. then I cried…

Advertisements

Yesterday, I published a method to format date duration calculations in plain English using javascript.

This time, I’m doing it in the XSL.

<!-- duration in days -->

 <xsl:variable name="duration"           select="number(event/scheduling/duration)" />
 <xsl:variable name="numDays"            select="format-number($duration         div (24 * 60 * 60 * 1000),'0')" />
 <xsl:variable name="leftOverDays"       select="              $duration         mod (24 * 60 * 60 * 1000)" />
 <xsl:variable name="numHours"           select="format-number($leftOverDays     div (     60 * 60 * 1000),'0')" />
 <xsl:variable name="leftOverHours"      select="              $leftOverDays     mod (     60 * 60 * 1000)" />
 <xsl:variable name="numMinutes"         select="format-number($leftOverHours    div (          60 * 1000),'0')" />
 <xsl:variable name="leftOverMinutes"    select="              $leftOverHours    mod (          60 * 1000)" />
 <xsl:variable name="numSeconds"         select="format-number($leftOverMinutes  div (               1000),'0')" />
 <xsl:variable name="numMiliSeconds"     select="              $leftOverMinutes  mod (               1000)" />

 <xsl:variable name="dayString"><xsl:choose>
 <xsl:when test="$numDays=1">1 Day</xsl:when>
 <xsl:when test="$numDays &gt; 0"><xsl:value-of select="$numDays" /> Days </xsl:when>
 </xsl:choose></xsl:variable>
 <xsl:variable name="hourString"><xsl:choose>
 <xsl:when test="$numHours=1">1 Hour </xsl:when>
 <xsl:when test="$numHours &gt; 0"><xsl:value-of select="$numHours" /> Hours </xsl:when>
 </xsl:choose></xsl:variable>
 <xsl:variable name="minuteString"><xsl:choose>
 <xsl:when test="$numMinutes=1">1 Minute </xsl:when>
 <xsl:when test="$numMinutes &gt; 0"><xsl:value-of select="$numMinutes" /> Minutes </xsl:when>
 </xsl:choose></xsl:variable>
 <xsl:variable name="secondString"><xsl:choose>
 <xsl:when test="$numSeconds=1">1 Second </xsl:when>
 <xsl:when test="$numSeconds &gt; 0"><xsl:value-of select="$numSeconds" /> Seconds </xsl:when>
 </xsl:choose></xsl:variable>
 <xsl:variable name="miliSecondString"><xsl:choose>
 <xsl:when test="$numMiliSeconds=1">1 MiliSecond </xsl:when>
 <xsl:when test="$numMiliSeconds &gt; 0"><xsl:value-of select="$numMiliSeconds" /> MiliSeconds </xsl:when>
 </xsl:choose></xsl:variable>

 <xsl:variable name="durationString">
 <xsl:value-of select="$dayString" />
 <xsl:value-of select="$hourString" />
 <xsl:value-of select="$minuteString" />
 <xsl:value-of select="$secondString" />
 <xsl:value-of select="$miliSecondString" />
 </xsl:variable>
 
 <xsl:value-of select="$durationString" />

I actually have to do it in XSL but I thought I’d get the first version in javascript to see how to do it first.

<script type="text/javascript">
 var date1=new Date("01 January 1970 00:00:00"); // a date in the past
 var date2=new Date(); // now
 var duration = Math.abs(date1.getTime() - date2.getTime());
 // some smart ass is going to say it does not deal with leap years. he'd be right. Talk to the hand :)
 var numYears        =Math.floor(duration            / (365 * 24 * 60 * 60 * 1000));
 var leftOverYears   =           duration            % (365 * 24 * 60 * 60 * 1000) ;
 var numDays         =Math.floor(leftOverYears       / (24 * 60 * 60 * 1000));
 var leftOverDays    =           leftOverYears       % (24 * 60 * 60 * 1000) ;
 var numHours        =Math.floor(leftOverDays        / (     60 * 60 * 1000));
 var leftOverHours   =           leftOverDays        % (     60 * 60 * 1000) ;
 var numMinutes      =Math.floor(leftOverHours       / (          60 * 1000));
 var leftOverMinutes =           leftOverHours       % (          60 * 1000) ;
 var numSeconds      =Math.floor(leftOverMinutes     / (               1000));
 var numMiliSeconds  =           leftOverMinutes     % (               1000) ;

 var durationString=null;
 var yearString="";
 var dayString="";
 var hourString="";
 var minuteString="";
 var secondString="";
 var miliSecondString="";

 if (numYears==1){yearString="1 Year ";} else if (numYears>0){yearString=numYears + " Years "}
 if (numDays==1){dayString="1 Day ";} else if (numDays>0){dayString=numDays + " Days "}
 if (numHours==1){hourString="1 Hour ";} else if (numHours>0){hourString=numHours + " Hours "}
 if (numMinutes==1){minuteString="1 Minute ";} else if (numMinutes>0){minuteString=numMinutes + " Minutes "}
 if (numSeconds==1){secondString="1 Second ";} else if (numSeconds>0){secondString=numSeconds + " Seconds "}
 if (numMiliSeconds==1){miliSecondString="1 MiliSecond ";} else if (numMiliSeconds>0){miliSecondString=numMiliSeconds + " MiliSeconds"}

 durationString = yearString + dayString + hourString + minuteString + secondString + miliSecondString;
 durationString.trim();
 prompt("duration: ",durationString)
 </script>

Tomorrow, the XSL for the same thing.

After resizing images, IE has been causing havoc once more. This thing is really buggy and should be ditched as soon as possible.

Internet explorer reports the wrong image size when viewing the image properties. God knows why.

To have a look at the right image size, right click on the image in the HTML document, select properties. Select the path of the image and open a new tab with the copied image url. Right click on the new image properties and view the correct width and height.

Alternatively, use firefox (or any other quality browser) to right click on the image and get the right image size.

Microsoft, I truly hate you for giving me work I shouldn’t have to be doing. I’ve got better things to do.

It’s so annoying. I had a for look in a javascript and it was blocking on the “<” sign of my for loop, causing an error. Here’s the fix:

<xsl:template match="/">
 <script type="text/javascript" language="javascript"><xsl:text disable-output-escaping="yes"><![CDATA[
   for (var i=0; i < someArray.length; i++){
      ...
   }
]]></xsl:text>
 </script>