Besides the correct answers you need for <xsl:include> or <xsl:import> (I would recommend the latter, as the former can often lead to duplication errors), another problem is the following
The function name must belong to the namespace .
The namespace must be declared (defined and prefixed) in the same file in which the function is defined.
Any function call must prefix the function name and the prefix must be bound to the same namespace to which the function name belongs
Here is a simple example:
I. The deleteA.xsl file defines the function my:double
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:my="my:my" > <xsl:function name="my:double" as="xs:double"> <xsl:param name="pArg" as="xs:double"/> <xsl:sequence select="2*$pArg"/> </xsl:function> </xsl:stylesheet>
II. The deleteB.xsl file imports the deleteB.xsl file and uses the my:double function:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:my="my:my"> <xsl:import href="deleteA.xsl"/> <xsl:output method="text"/> <xsl:template match="/"> <xsl:sequence select="my:double(.)"/> </xsl:template> </xsl:stylesheet>
III. The conversion contained in deleteB.xsl applies to the following XML document :
<t>1</t>
and the correct result is obtained :
2
Additional comment . The browser does not currently support XSLT 2.0 conversions. xsl:function is only available in XSLT 2.0+.
Dimitre novatchev
source share