-3

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>
Sicco
  • 6,167
  • 5
  • 45
  • 61
Nandha Kumar
  • 126
  • 2
  • 5
  • 1
    Also tell us which XSLT processor you use as `xsl:function` is a new feature in XSLT 2.0 which is not supported in any XSLT 1.0 processor of course. So unless you use Saxon 9 or AltovaXML or XQSharp or the XSLT 2.0 processors IBM and Intel provide you can't use `xsl:function`. – Martin Honnen Dec 08 '11 at 11:23
  • 2
    Downvoted the question: telling us there is an error, without telling us what the error is, is not helpful. – Michael Kay Dec 08 '11 at 11:30

2 Answers2

1

The function defined in the question is syntactically correct and seems meaningful.

Therefore, the error is in the code that you forgot to show to us -- more specifically how this function is being used with what arguments.

Apart from this, there are obvious refactoring possibilities -- such as replacing the unnecessary string-join() with concat().

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
0

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)"/>).

Emma Burrows
  • 4,734
  • 1
  • 20
  • 24