[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

difference between MSXSL:SCRIPT and XSL:CALL-TEMPLATE

Subject: difference between MSXSL:SCRIPT and XSL:CALL-TEMPLATE
From: "Todd Binder" <todd_binder@xxxxxxxxxxx>
Date: Thu, 6 Dec 2001 12:14:36 -0500
date difference using vbscript
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@xxxxxxxxxxx

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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.