home contribute faq download

FunctX XSLT Functions

functx:timezone-from-duration

Converts an xs:dayTimeDuration into a timezone like "-05:00" or "Z"

Google
Webxsltfunctions.com

Description

The functx:timezone-from-duration function accepts an xs:dayTimeDuration and converts it to a timezone value (formatted as it appears in xs:date, xs:time, xs:dateTime etc. values). The dayTimeDuration may only have the hours (H) component (or the seconds component if the value is PT0S) and must be between -PT14H and PT14H inclusive.

Arguments and Return Type

NameTypeDescription
$duration xs:dayTimeDuration the duration
return value xs:string

XSLT Function Declaration

See XQuery definition.
<xsl:function name="functx:timezone-from-duration" as="xs:string"
              xmlns:functx="http://www.functx.com">
  <xsl:param name="duration" as="xs:dayTimeDuration"/>

  <xsl:sequence select="
   if (string($duration) = ('PT0S','-PT0S'))
   then 'Z'
   else if (matches(string($duration),'-PT[1-9]H'))
   then replace(string($duration),'PT([1-9])H','0$1:00')
   else if (matches(string($duration),'PT[1-9]H'))
   then replace(string($duration),'PT([1-9])H','+0$1:00')
   else if (matches(string($duration),'-PT1[0-4]H'))
   then replace(string($duration),'PT(1[0-4])H','$1:00')
   else if (matches(string($duration),'PT1[0-4]H'))
   then replace(string($duration),'PT(1[0-4])H','+$1:00')
   else error(xs:QName('functx:Invalid_Duration_Value'))
 "/>

</xsl:function>

Examples

XPath ExampleResults
functx:timezone-from-duration(
     xs:dayTimeDuration('PT0S'))
Z
functx:timezone-from-duration(
     xs:dayTimeDuration('-PT5H'))
-05:00
functx:timezone-from-duration(
     xs:dayTimeDuration('PT9H'))
+09:00

See Also

functx:duration-from-timezoneConverts a timezone like "-05:00" or "Z" into xs:dayTimeDuration
fn:timezone-from-timeThe timezone portion of a time
fn:timezone-from-dateTimeThe timezone portion of a date/time

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26Priscilla Walmsley, Datypic, pwalmsley@datypic.com, http://www.datypic.com
Datypic XSLT Services

Recommended Reading:

XQuery