home contribute faq download

FunctX XSLT Functions

functx:pad-integer-to-length

Pads an integer to a desired length by adding leading zeros

Google
Webdatypic.com

Description

The functx:pad-integer-to-length function returns $integerToPad concatenated with enough leading zeros to make its length $length. The function will raise an error if $integerToPad is longer than $length.

Arguments and Return Type

NameTypeDescription
$integerToPad xs:anyAtomicType? the integer to pad
$length xs:integer the desired length
return value xs:string

XSLT Function Declaration

See XQuery definition.
<xsl:function name="functx:pad-integer-to-length" as="xs:string"
              xmlns:functx="http://www.functx.com">
  <xsl:param name="integerToPad" as="xs:anyAtomicType?"/>
  <xsl:param name="length" as="xs:integer"/>

  <xsl:sequence select="
   if ($length &lt; string-length(string($integerToPad)))
   then error(xs:QName('functx:Integer_Longer_Than_Length'))
   else concat
         (functx:repeat-string(
            '0',$length - string-length(string($integerToPad))),
          string($integerToPad))
 "/>

</xsl:function>

Examples

XPath ExampleResults
functx:pad-integer-to-length(12, 6)
000012
functx:pad-integer-to-length(1, 6)
000001
functx:pad-integer-to-length(12, 2)
12

Depends On

functx:repeat-stringRepeats a string a given number of times

See Also

functx:pad-string-to-lengthPads a string to a desired length
functx:repeat-stringRepeats a string a given number of times

History

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

Recommended Reading:

XQuery