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| Name | Type | Description |
$integerToPad |
xs:anyAtomicType? |
the integer to pad |
$length |
xs:integer |
the desired length |
| return value |
xs:string |
XQuery Function Declaration| See XSLT definition. | | XQuery Syntax for January 2007 (1.0): |
|---|
declare namespace functx = "http://www.functx.com";
declare function functx:pad-integer-to-length
( $integerToPad as xs:anyAtomicType? ,
$length as xs:integer ) as xs:string {
if ($length < 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))
} ; | | XQuery Syntax for July 2004 - November 2005 (CR): |
|---|
declare namespace functx = "http://www.functx.com";
declare function functx:pad-integer-to-length
( $integerToPad as xdt:anyAtomicType? ,
$length as xs:integer ) as xs:string {
if ($length < 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))
} ; | | XQuery Syntax for May 2003: |
|---|
declare namespace functx = "http://www.functx.com"
define function pad-integer-to-length
( $integerToPad as xdt:anyAtomicType? ,
$length as xs:integer ) as xs:string {
if ($length < fn:string-length(fn:string($integerToPad)))
then fn:error(xs:QName('functx:Integer_Longer_Than_Length'))
else fn:concat
(functx:repeat-string(
'0',$length - fn:string-length(fn:string($integerToPad))),
fn:string($integerToPad))
} |
Examples| XQuery Example | Results |
|---|
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 OnSee AlsoHistory |
|