This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
difference between MSXSL:SCRIPT and XSL:CALL-TEMPLATE
- From: "Todd Binder" <todd_binder at hotmail dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Thu, 6 Dec 2001 12:14:36 -0500
- Subject: [xsl] difference between MSXSL:SCRIPT and XSL:CALL-TEMPLATE
- Reply-to: xsl-list at lists dot mulberrytech dot com
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 < 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 > 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