I have a XSLT style sheet for transforming. In this I have to specify user defined function using <xsl:function>. When I am about to do this within this <xsl:stylesheet></xsl:stylesheet> it throws an error.
Here is the function:
<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>
As @John Mitchell said, telling us what the error is might be helpful. However, I see you have the namespace declared on the function - make sure
xmlns:functx="http://www.functx.com"is also declared in the<xsl:stylesheet>element at the top of your stylesheet.Another thing to check, obviously, is that you're entering your arguments correctly in the function call: your first two parameters will need quotes but the third doesn't (eg
<xsl:value-of select="functx:pad-string-to-length('boo', '-', 12)"/>).