This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

difference between MSXSL:SCRIPT and XSL:CALL-TEMPLATE


i have a need to format a time value that is getting passed in HH:MM in H:MM
AM/PM format within some XSL

i am using MSXSL:SCRIPT already to determine the current date for use
elsewhere in the XSL document, so my question is, which of the following
would be better (or are they basically equal in this case?)

1) using VBSCRIPT within the MSXSL:SCRIPT
'tm is passed in as HH:MM, i.e. 13:00 would represent 1:00 PM

 function converttime(tm)
  timeval = timevalue(tm)

  am = " AM"
  pm = " PM"

  hr = hour(timeval)
  if hr > 12 then
   hr = hr - 12
   ampm = pm

  elseif hr = 0 then
   hr = 12
   ampm = am

  elseif hr < 12 then
   ampm = am

  else
   ampm = pm

  end if

  min = minute(timeval)
  if len(min) = 1 then min = "0" + cstr(min)

  converttime = cstr(hr) + ":" + cstr(min) + ampm
 end function

HERE IS HOW THE FUNCTION WOULD BE CALLED FROM WITHIN THE XSL TEMPLATE

   <xsl:for-each select="time">
<!-- the following uses VBSCRIPT to format the date -->
     <xsl:value-of select="user:converttime(string(text()))"/>
   </xsl:for-each>

or

2) native XSL

 <xsl:template name="convertTime">
  <xsl:param name="timeValue"/>

   <xsl:variable name="timeHour" select="number(substring($timeValue, 1,
2))"/>
   <xsl:variable name="timeMinute" select="substring($timeValue, 4, 2)"/>

   <xsl:choose>
    <xsl:when test="$timeHour = 12">
  <xsl:value-of select="$timeHour"/>
  <xsl:text>:</xsl:text>
  <xsl:value-of select="$timeMinute"/>
  <xsl:text> PM</xsl:text>

    </xsl:when>
    <xsl:when test="$timeHour = 24">
  <xsl:value-of select="number($timeHour) - 12"/>
  <xsl:text>:</xsl:text>
  <xsl:value-of select="$timeMinute"/>
  <xsl:text> AM</xsl:text>

    </xsl:when>
    <xsl:when test="$timeHour &lt; 12">
  <xsl:value-of select="$timeHour"/>
  <xsl:text>:</xsl:text>
  <xsl:value-of select="$timeMinute"/>
  <xsl:text> AM</xsl:text>

    </xsl:when>
    <xsl:when test="$timeHour &gt; 12">
  <xsl:value-of select="number($timeHour) - 12"/>
  <xsl:text>:</xsl:text>
  <xsl:value-of select="$timeMinute"/>
  <xsl:text> PM</xsl:text>

    </xsl:when>
    <xsl:otherwise>
  <xsl:value-of select="concat('[invalid time: ',
  '$timeValue')"/>

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

 </xsl:template>

HERE IS HOW THE TEMPLATE WOULD BE CALLED FROM WITHIN THE XSL DOCUMENT

   <xsl:for-each select="time">

<!-- the following uses XSL to format the date -->
     <xsl:call-template name="convertTime">
      <xsl:with-param name="timeValue" select="text()"/>
     </xsl:call-template>
   </xsl:for-each>


is there a difference?

- todd

Todd Binder
todd_binder@hotmail.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]