home contribute faq download

FunctX XSLT Functions

functx:pad-string-to-length

Pads a string to a desired length

Google
Webdatypic.com

Description

The functx:pad-string-to-length function returns $stringToPad appended with enough repetitions of $padChar to make its length $length. The function will truncate $stringToPad if its length is greater than $length.

Arguments and Return Type

NameTypeDescription
$stringToPad xs:string? the string to pad
$padChar xs:string the character(s) to use as padding
$length xs:integer the desired length
return value xs:string

XSLT Function Declaration

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

  <xsl:sequence select="
   substring(
     string-join (
       ($stringToPad, for $i in (1 to $length) return $padChar)
       ,'')
    ,1,$length)
 "/>

</xsl:function>

Examples

XPath ExampleResults
functx:pad-string-to-length('abc', '*', 6)
abc***
functx:pad-string-to-length('abcdef', '*', 4)
abcd
functx:pad-string-to-length('', '*', 4)
****

See Also

functx:pad-integer-to-lengthPads an integer to a desired length by adding leading zeros
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