[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

problem with xsl:import and namespaces

Subject: problem with xsl:import and namespaces
From: Jostein Austvik Jacobsen <josteinaj@xxxxxxxxx>
Date: Tue, 17 Aug 2010 14:19:52 +0200
 problem with xsl:import and namespaces
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.