[xsl] problem with xsl:import and namespaces

Subject: [xsl] problem with xsl:import and namespaces
From: Jostein Austvik Jacobsen <josteinaj@xxxxxxxxx>
Date: Tue, 17 Aug 2010 14:19:52 +0200
Hi all.

I've got five stylesheets, where test.xsl imports A.xsl and B.xsl,
A.xsl imports C1.xsl, and B.xsl imports C2.xsl. C1.xsl and C2.xsl is
in the same namespace, and defining the same function (i.e. C2.xsl is
a newer version of C1.xsl). Now, I wouldn't think that this would
cause a problem, as C1.xsl and C2.xsl is not imported directly into
the same stylesheet. test.xsl only makes use of C1.xsl and C2.xsl
indirectly via A.xsl and B.xsl, not knowing that there are multiple
versions of C (or that A.xsl and B.xsl uses C for that matter.)

However, when importing B.xsl after A.xsl in test.xsl, then the
function in C1.xsl is overridden by the one in C2.xsl, even when
called from A.xsl... Here's the code:

---- test.xsl start ----
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
				xmlns:A="http://www.example.org/A";
				xmlns:B="http://www.example.org/B";
				exclude-result-prefixes="#all"
				version="2.0">
	
	<xsl:import href="A.xsl"/>
	<xsl:import href="B.xsl"/>
	
	<xsl:output omit-xml-declaration="yes"/>
	
	<xsl:template match="/" name="main">
		<tests>
			<test1>
				<xsl:sequence select="A:hello('test1')"/>
			</test1>
			<test2>
				<xsl:sequence select="B:hello('test2')"/>
			</test2>
		</tests>
	</xsl:template>
	
</xsl:stylesheet>
---- test.xsl end ----

---- A.xsl start ----
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
				xmlns:xs="http://www.w3.org/2001/XMLSchema";
				xmlns:A="http://www.example.org/A";
				xmlns:C="http://www.example.org/C";
				version="2.0">
	
	<xsl:import href="C1.xsl"/>
	
	<xsl:function name="A:hello" as="xs:string">
		<xsl:param name="who" as="xs:string"/>
		<xsl:sequence select="C:hello($who)"/>
	</xsl:function>
	
</xsl:stylesheet>
---- A.xsl end ----

---- B.xsl start ----
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
				xmlns:xs="http://www.w3.org/2001/XMLSchema";
				xmlns:B="http://www.example.org/B";
				xmlns:C="http://www.example.org/C";
				version="2.0">
	
	<xsl:import href="C2.xsl"/>
	
	<xsl:function name="B:hello" as="xs:string">
		<xsl:param name="who" as="xs:string"/>
		<xsl:sequence select="C:hello($who)"/>
	</xsl:function>
	
</xsl:stylesheet>
---- B.xsl end ----

---- C1.xsl start ----
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:xs="http://www.w3.org/2001/XMLSchema";
                xmlns:C="http://www.example.org/C";
                version="2.0">

   <xsl:function name="C:hello" as="xs:string">
      <xsl:param name="who" as="xs:string"/>
      <xsl:sequence select="concat('C1 says: Hello, ', $who, '!')"/>
   </xsl:function>

</xsl:stylesheet>
---- C1.xsl end ----

---- C2.xsl start ----
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:xs="http://www.w3.org/2001/XMLSchema";
                xmlns:C="http://www.example.org/C";
                version="2.0">

   <xsl:function name="C:hello" as="xs:string">
      <xsl:param name="who" as="xs:string"/>
      <xsl:sequence select="concat('C2 says: Hello, ', $who, '!')"/>
   </xsl:function>

</xsl:stylesheet>
---- C2.xsl end ----

The output is:
<tests>
    <test1>C2 says: Hello, test1!</test1>
    <test2>C2 says: Hello, test2!</test2>
</tests>

I had expected:
<tests>
    <test1>C1 says: Hello, test1!</test1>
    <test2>C2 says: Hello, test2!</test2>
</tests>

I guess there's something I've missed about xsl:import and namespaces
- or maybe there's an error in my code?

Best Regards
Jostein Austvik Jacobsen

Current Thread