home contribute faq download

FunctX XSLT Functions

functx:insert-string

Inserts a string at a specified position

Google
Webdatypic.com

Description

The functx:insert-string function inserts a string ($stringToInsert) into another string ($originalString) at a specified position (which is 1-based). If the position is greater than the length of $originalString, it concatenates $stringToInsert at the end.

Arguments and Return Type

NameTypeDescription
$originalString xs:string? the original string to insert into
$stringToInsert xs:string? the string to insert
$pos xs:integer the position
return value xs:string

XSLT Function Declaration

See XQuery definition.
<xsl:function name="functx:insert-string" as="xs:string"
              xmlns:functx="http://www.functx.com">
  <xsl:param name="originalString" as="xs:string?"/>
  <xsl:param name="stringToInsert" as="xs:string?"/>
  <xsl:param name="pos" as="xs:integer"/>

  <xsl:sequence select="
   concat(substring($originalString,1,$pos - 1),
             $stringToInsert,
             substring($originalString,$pos))
 "/>

</xsl:function>

Examples

XPath ExampleResults
functx:insert-string('xyz','def',2)
xdefyz
functx:insert-string('xyz','def',5)
xyzdef
functx:insert-string('xyz','',2)
xyz
functx:insert-string('','def',2)
def

See Also

functx:index-of-stringThe position(s) of a substring

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