user1633145
user1633145

Reputation: 1

XSLT/XML date is formatting incorrectly in firefox (showing   between words)

I'm using editing XSLT templates that will that will be used to display price/odds in betting offices. The XML file contains a date that I needs to be displayed in the html. This displays exactly as intended in internet explorer, but when I open the XML file in firefox, the literal entity reference   is displayed instead of a non-breaking space.

Firefox (top) / IE (bottom)

<competition status="O" id="1" name="STEVENAGE v TORQUAY" shortname="STEVENAG-TORQUAY" description="STEVENAGE v TORQUAY" startdatetime="2011-05-25T00:00" enddatetime="2011-05-25T00:00" venue="" leaguename="" country="">

It's displaying the startdatetime attribute to the screen. Has anybody came across this problem before / understand why it's displaying &nbsp; instead of a space? Any help would be greatly appreciated.

Here is the code (XSLT) containing the time DIV

<xsl:if test="$displayTimeTitle=1">
          <div class="TIME editable" id="timeHeader">
            <div class="TIMETEXT">
              <xsl:call-template name="wysiwyg:doAttributes">
                <xsl:with-param name="WYSIWYG" select="$WYSIWYG" />
                <xsl:with-param name="pItem" select="//competition[1]/@startdatetime" />
              </xsl:call-template>
              <xsl:choose>
                <xsl:when test="//competition[1]/edited[@name='startdatetime']">
                  <xsl:value-of select="//competition[1]/@startdatetime"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:if test="//competition[1]/@startdatetime !=''">
                    <xsl:call-template name="doMM_Date">
                      <xsl:with-param name="Date">
                        <xsl:call-template name="Time_Add">
                          <xsl:with-param name="Date" select="//competition[1]/@startdatetime"/>
                          <xsl:with-param name="AddMinutes" select="$timeadjustment"/>
                        </xsl:call-template>
                      </xsl:with-param>
                      <xsl:with-param name="languagecode" select="E"/>
                    </xsl:call-template>
                  </xsl:if>
                  <xsl:if test="$displayHeaderAMPM=1">
                    <nobr>
                      <xsl:value-of select="$headerAMPM"/>
                    </nobr>
                  </xsl:if>
                </xsl:otherwise>
              </xsl:choose>
            </div>
          </div>
        </xsl:if>

And here is the external style sheet Date_Time_Templates.xsl that contains the templates like doMM_Date as shown above

<?xml version="1.0"?>
<!-- (C) Copyright 2DB Limited 2012. No part of this document can be reproduced without the express written permission of 2DB Limited. -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template name="Time_Add">
    <xsl:param name="Date"/>
    <xsl:param name="AddMinutes"/>

    <xsl:param name="year">
        <xsl:choose>
            <xsl:when test="contains($Date,'-')">
                <xsl:value-of select="substring($Date,1,4)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="substring($Date,7,4)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:param>
    <xsl:param name="month">
        <xsl:choose>
            <xsl:when test="contains($Date,'-')">
                <xsl:value-of select="substring($Date,6,2)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="substring($Date,4,2)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:param>
    <xsl:param name="day">
        <xsl:choose>
            <xsl:when test="contains($Date,'-')">
                <xsl:value-of select="substring($Date,9,2)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="substring($Date,1,2)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:param>

    <xsl:param name="hour" select="substring($Date,12,2)"/>
    <xsl:param name="minute" select="substring($Date,15,2)"/>
    <xsl:variable name="newhour">
        <xsl:choose>
            <xsl:when test="($hour + ($AddMinutes div 60)) &gt; 23">
                <xsl:value-of select="($hour + ($AddMinutes div 60)) - 24"/>
            </xsl:when>
            <xsl:when test="($hour + ($AddMinutes div 60)) &lt; 00">
                <xsl:value-of select="($hour + ($AddMinutes div 60)) + 24"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="($hour + ($AddMinutes div 60))"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:variable name="tempday">
        <xsl:choose>
            <xsl:when test="($hour + ($AddMinutes div 60)) &gt; 23">
                <xsl:value-of select="$day + 1"/>
            </xsl:when>
            <xsl:when test="($hour + ($AddMinutes div 60)) &lt; 00">
                <xsl:value-of select="$day - 1"/>

            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$day"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:variable name="newday">
        <xsl:choose>
            <xsl:when test="($month='01' or $month='03' or $month='05' or $month='08' or $month='10' or $month='12') and  $tempday &gt; 31">
                <xsl:value-of select="01"/>
            </xsl:when>
            <xsl:when test="($month='04' or $month='06' or $month='09' or $month='11') and  $tempday &gt; 30">
                <xsl:value-of select="01"/>
            </xsl:when>
            <xsl:when test="($month='02') and  $tempday &gt; 28">
                <xsl:value-of select="01"/>
            </xsl:when>
            <xsl:when test="($month='02' or $month='04' or $month='06' or $month='09' or $month='11' or $month='01') and $tempday = 00">
                <xsl:value-of select="31"/>
            </xsl:when>
            <xsl:when test="($month='05' or $month='07' or $month='10' or $month='12') and $tempday = 00">
                <xsl:value-of select="30"/>
            </xsl:when>
            <xsl:when test="($month='03') and $tempday = 00">
                <xsl:value-of select="28"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$tempday"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:variable name="tempmonth">
        <xsl:choose>
            <xsl:when test="($newday = 01 or $newday = 1) and $newday != $day and $day != 02">
                <xsl:value-of select="$month + 1"/>
            </xsl:when>
            <xsl:when test="($newday = 31 or $newday = 28 or $newday = 30) and $newday != $day and $day != 02">
                <xsl:value-of select="$month - 1"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$month"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:variable name="newmonth">
        <xsl:choose>
            <xsl:when test="$tempmonth &gt; 12">
                <xsl:value-of select="01"/>
            </xsl:when>
            <xsl:when test="$tempmonth = 00">
                <xsl:value-of select="12"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$tempmonth"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:variable name="newyear">
        <xsl:choose>
            <xsl:when test="($newmonth = 01 or newmonth = 1) and $newmonth != $month">
                <xsl:value-of select="$year + 1"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$year"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:variable name="finalday">
        <xsl:choose>
            <xsl:when test="string-length($newday) = 1">0<xsl:value-of select="$newday"></xsl:value-of></xsl:when>
            <xsl:otherwise><xsl:value-of select="$newday"></xsl:value-of></xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="finalmonth">
        <xsl:choose>
            <xsl:when test="string-length($newmonth) = 1">0<xsl:value-of select="$newmonth"></xsl:value-of></xsl:when>
            <xsl:otherwise><xsl:value-of select="$newmonth"></xsl:value-of></xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="finalhour">
        <xsl:choose>
            <xsl:when test="string-length($newhour) = 1">0<xsl:value-of select="$newhour"></xsl:value-of></xsl:when>
            <xsl:otherwise><xsl:value-of select="$newhour"></xsl:value-of></xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:value-of select="$finalday"/>/<xsl:value-of select="$finalmonth"/>/<xsl:value-of select="$newyear"/>/<xsl:value-of select="$finalhour"/>:<xsl:value-of select="$minute"/>

</xsl:template>

<xsl:template name="Time_Add_NoDate">
    <xsl:param name="Date"/>
    <xsl:param name="AddMinutes"/>


    <xsl:param name="hour" select="substring($Date,1,2)"/>
    <xsl:param name="minute" select="substring($Date,4,2)"/>
    <xsl:variable name="newhour">
        <xsl:choose>
            <xsl:when test="($hour + ($AddMinutes div 60)) &gt; 23">
                <xsl:value-of select="($hour + ($AddMinutes div 60)) - 24"/>
            </xsl:when>
            <xsl:when test="($hour + ($AddMinutes div 60)) &lt; 00">
                <xsl:value-of select="($hour + ($AddMinutes div 60)) + 24"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="($hour + ($AddMinutes div 60))"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>


    <xsl:variable name="finalhour">
        <xsl:choose>
            <xsl:when test="string-length($newhour) = 1">0<xsl:value-of select="$newhour"></xsl:value-of></xsl:when>
            <xsl:otherwise><xsl:value-of select="$newhour"></xsl:value-of></xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:call-template name="TwentyFourToTwelveHrClock">
        <xsl:with-param name="Time"><xsl:value-of select="$finalhour"/>:<xsl:value-of select="$minute"/></xsl:with-param>
    </xsl:call-template>




</xsl:template>


<xsl:template name="Date_Day">

    <xsl:param name="Date"/>
    <xsl:param name="year">
        <xsl:choose>
            <xsl:when test="contains($Date,'-')">
                <xsl:value-of select="substring($Date,1,4)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="substring($Date,7,4)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:param>
    <xsl:param name="month">
        <xsl:choose>
            <xsl:when test="contains($Date,'-')">
                <xsl:value-of select="substring($Date,6,2)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="substring($Date,4,2)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:param>
    <xsl:param name="day">
        <xsl:choose>
            <xsl:when test="contains($Date,'-')">
                <xsl:value-of select="substring($Date,9,2)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="substring($Date,1,2)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:param>

    <!--<xsl:value-of select="$year"/>-->
    <xsl:variable name="a" select="floor((14 - $month) div 12)"/>
        <xsl:variable name="y" select="$year - $a"/>
        <xsl:variable name="m" select="$month + 12 * $a - 2"/>
    <xsl:variable name="WkDay" select="($day + $y + floor($y div 4) - floor($y div 100) + floor($y div 400) + floor((31 * $m) div 12)) mod 7"/>

     <xsl:choose>
        <xsl:when test="$WkDay = 0">Sunday</xsl:when>
        <xsl:when test="$WkDay = 1">Monday</xsl:when>
        <xsl:when test="$WkDay = 2">Tuesday</xsl:when>
          <xsl:when test="$WkDay = 3">Wednesday</xsl:when>
          <xsl:when test="$WkDay = 4">Thursday</xsl:when>
          <xsl:when test="$WkDay = 5">Friday</xsl:when>
          <xsl:when test="$WkDay = 6">Saturday</xsl:when>
          <xsl:otherwise>error: <xsl:value-of select="$WkDay"/></xsl:otherwise>
    </xsl:choose>

</xsl:template>

  <xsl:template name="Date_Day2">

    <xsl:param name="Date"/>
    <xsl:param name="year">
        <xsl:choose>
            <xsl:when test="contains($Date,'-')">
                <xsl:value-of select="substring($Date,1,4)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="substring($Date,7,4)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:param>
    <xsl:param name="month">
        <xsl:choose>
            <xsl:when test="contains($Date,'-')">
                <xsl:value-of select="substring($Date,6,2)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="substring($Date,4,2)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:param>
    <xsl:param name="day">
        <xsl:choose>
            <xsl:when test="contains($Date,'-')">
                <xsl:value-of select="substring($Date,9,2)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="substring($Date,1,2)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:param>

    <xsl:variable name="a" select="floor((14 - $month) div 12)"/>
    <xsl:variable name="y" select="$year - $a"/>
    <xsl:variable name="m" select="$month + 12 * $a - 2"/>
    <xsl:variable name="WkDay" select="($day + $y + floor($y div 4) - floor($y div 100) + floor($y div 400) + floor((31 * $m) div 12)) mod 7"/>

    <xsl:choose>
      <xsl:when test="$WkDay = 0">Sun </xsl:when>
      <xsl:when test="$WkDay = 1">Mon </xsl:when>
      <xsl:when test="$WkDay = 2">Tue </xsl:when>
      <xsl:when test="$WkDay = 3">Wed </xsl:when>
      <xsl:when test="$WkDay = 4">Thu </xsl:when>
      <xsl:when test="$WkDay = 5">Fri </xsl:when>
      <xsl:when test="$WkDay = 6">Sat </xsl:when>
      <xsl:otherwise>
        error: <xsl:value-of select="$WkDay"/>
      </xsl:otherwise>
    </xsl:choose>

  </xsl:template>


<xsl:template name="doMM_Date">
<xsl:param name="Date"/>

            <xsl:call-template name="Date_Day_MM"><xsl:with-param name="Date" select="$Date"/></xsl:call-template>
            <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>

            <xsl:value-of select="substring($Date, 1, 2)"/>
            <xsl:call-template name="StNd"><xsl:with-param name="Day" select="substring($Date, 1, 2)"/></xsl:call-template>

            <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
            <xsl:call-template name="Date_Month_MM"><xsl:with-param name="Date" select="$Date"/></xsl:call-template> 

            <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
            <xsl:call-template name="TwentyFourToTwelveHrClock">
                <xsl:with-param name="Time"><xsl:value-of select="substring($Date, 12, 5)"/></xsl:with-param>
            </xsl:call-template>


</xsl:template>         


<xsl:template name="Date_Day_MM">
    <xsl:param name="Date"/>

    <xsl:param name="year">
        <xsl:choose>
            <xsl:when test="contains($Date,'-')">
                <xsl:value-of select="substring($Date,1,4)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="substring($Date,7,4)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:param>
    <xsl:param name="month">
        <xsl:choose>
            <xsl:when test="contains($Date,'-')">
                <xsl:value-of select="substring($Date,6,2)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="substring($Date,4,2)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:param>
    <xsl:param name="day">
        <xsl:choose>
            <xsl:when test="contains($Date,'-')">
                <xsl:value-of select="substring($Date,9,2)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="substring($Date,1,2)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:param>

    <xsl:variable name="a" select="floor((14 - $month) div 12)"/>
        <xsl:variable name="y" select="$year - $a"/>
        <xsl:variable name="m" select="$month + 12 * $a - 2"/>
    <xsl:variable name="WkDay" select="($day + $y + floor($y div 4) - floor($y div 100) + floor($y div 400) + floor((31 * $m) div 12)) mod 7"/>

     <xsl:choose>
        <xsl:when test="$WkDay = 0">Sunday</xsl:when>
        <xsl:when test="$WkDay = 1">Monday</xsl:when>
        <xsl:when test="$WkDay = 2">Tuesday</xsl:when>
          <xsl:when test="$WkDay = 3">Wednesday</xsl:when>
          <xsl:when test="$WkDay = 4">Thursday</xsl:when>
          <xsl:when test="$WkDay = 5">Friday</xsl:when>
          <xsl:when test="$WkDay = 6">Saturday</xsl:when>
          <xsl:otherwise></xsl:otherwise>
    </xsl:choose>



</xsl:template>

<xsl:template name="Date_Month_MM">

    <xsl:param name="Date"/>
    <xsl:param name="month">
        <xsl:choose>
            <xsl:when test="contains($Date,'-')">
                <xsl:value-of select="substring($Date,6,2)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="substring($Date,4,2)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:param>



     <xsl:choose>
        <xsl:when test="$month = 1 or $month = 01">January</xsl:when>
        <xsl:when test="$month = 2 or $month = 02">February</xsl:when>
        <xsl:when test="$month = 3 or $month = 03">March</xsl:when>
        <xsl:when test="$month = 4 or $month = 04">April</xsl:when>
        <xsl:when test="$month = 5 or $month = 05">May</xsl:when>
        <xsl:when test="$month = 6 or $month = 06">June</xsl:when>
        <xsl:when test="$month = 7 or $month = 07">July</xsl:when>
        <xsl:when test="$month = 8 or $month = 08">August</xsl:when>
        <xsl:when test="$month = 9 or $month = 09">September</xsl:when>
        <xsl:when test="$month = 10">October</xsl:when>
        <xsl:when test="$month = 11">November</xsl:when>
        <xsl:when test="$month = 12">December</xsl:when>
        <xsl:otherwise></xsl:otherwise>
    </xsl:choose>

</xsl:template>


<xsl:template name="Sh_Month">

    <xsl:param name="Month"/>
    <xsl:choose>
        <xsl:when test="$Month = 01">January</xsl:when>
        <xsl:when test="$Month = 02">February</xsl:when>
        <xsl:when test="$Month = 03">March</xsl:when>
        <xsl:when test="$Month = 04">April</xsl:when>
        <xsl:when test="$Month = 05">May</xsl:when>
        <xsl:when test="$Month = 06">June</xsl:when>
        <xsl:when test="$Month = 07">July</xsl:when>
        <xsl:when test="$Month = 08">August</xsl:when>
        <xsl:when test="$Month = 09">September</xsl:when>
        <xsl:when test="$Month = 10">October</xsl:when>
        <xsl:when test="$Month = 11">November</xsl:when>
        <xsl:when test="$Month = 12">December</xsl:when>
        <xsl:otherwise>error: <xsl:value-of select="$Month"/></xsl:otherwise>

    </xsl:choose>

</xsl:template>

<xsl:template name="StNd">
    <xsl:param name="Day"/>
        <xsl:if test="$Day != ''">
        <xsl:choose>
            <xsl:when test="$Day = 01">st</xsl:when>
            <xsl:when test="$Day = 02">nd</xsl:when>
            <xsl:when test="$Day = 03">rd</xsl:when>
            <xsl:when test="$Day = 21">st</xsl:when>
            <xsl:when test="$Day = 22">nd</xsl:when>
            <xsl:when test="$Day = 23">rd</xsl:when>
            <xsl:when test="$Day = 31">st</xsl:when>
            <xsl:otherwise>th</xsl:otherwise>
        </xsl:choose>
        </xsl:if>
</xsl:template>


<!--
    This Template Converts a time to 12 hour clock from 24 in the format HH:MM.
    Use the xsl:call-template name="TwentyFourToTwelveHrClock"><xsl:with-param name="Time" select="HH:MM"/>" 
 -->

<xsl:template name="TwentyFourToTwelveHrClock">
    <xsl:param name="Time"/>
    <xsl:choose>
        <xsl:when test="substring($Time,1,2) &gt; 12">
            <xsl:value-of select="substring($Time,1,2) - 12" />
            <xsl:value-of select="substring($Time,3,3)" />
        </xsl:when>
        <xsl:otherwise> <!-- nothing to do as am, output as normal -->
            <xsl:value-of select="substring($Time,1,5)"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>


</xsl:stylesheet>

Upvotes: 0

Views: 399

Answers (1)

Sean B. Durkin
Sean B. Durkin

Reputation: 12729

In at least some versions of FF, xsl:text with DOE does not work. This is a bug in FF. Your style-sheet is making extensive use of xsl:text+DOE . I advise reworking the style-sheet so it does not use any DOE. This should be a trivial exercise.

Side note

Of all the browsers, FF is the worst for XSLT support. What a tragedy, considering the lead role FF played for so many years in pushing the boundaries for browsers. Even that piece of rubbish malware, MS Internet Exploder, has better XSLT support than FF. Oh - the ignominy!

Upvotes: 2

Related Questions