Project

Profile

Help

Bug #3367

Updated by Michael Kay over 7 years ago

Trivial example: 
 I have packageA,  
 package, which uses packageA 
 transform, which call function from packageB. 

 packageA: 
 <pre> 
 <xsl:package name="http://www.ctk.cz/A/"  
	 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0" 
	 xmlns:xs="http://www.w3.org/2001/XMLSchema" 
	 xmlns:pA="http://www.ctk.cz/A/"> 

	 <xsl:function name="pA:helper" as="xs:string"> 
		 <xsl:sequence select="'Prague'"/> 
	 </xsl:function> 

	 <xsl:function name="pA:fA" as="xs:string" visibility="public"> 
		 <xsl:sequence select="pA:helper()"/> 
	 </xsl:function> 
 </xsl:package> 
 </pre> 

 PackageB: 
 <pre> 
 <xsl:package name="http://www.ctk.cz/B/"  
	 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0" 
	 xmlns:xs="http://www.w3.org/2001/XMLSchema" 
	 xmlns:pA="http://www.ctk.cz/A/" xmlns:pB="http://www.ctk.cz/B/"> 
	 <xsl:use-package name="http://www.ctk.cz/A/"/> 
	 <xsl:function name="pB:fB" as="xs:string" visibility="public"> 
		 <xsl:sequence select="pA:fA()"/> 
	 </xsl:function> 
 </xsl:package> 
 </pre> 

 transform: 
 <pre> 
 <xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version="3.0" 
                     xmlns:xs="http://www.w3.org/2001/XMLSchema" 
                     xmlns:pB="http://www.ctk.cz/B/"> 
                    
                     <xsl:use-package name='http://www.ctk.cz/B/'/> 
                     <xsl:template name="xsl:initial-template" as="xs:string"> 
                         <xsl:sequence select="pB:fB()"/> 
                         </xsl:template> 
                  </xsl:stylesheet> 
 </pre> 

 C# function to call transform: 
 <pre> 
 Processor processor = new Processor(true); 

             XsltCompiler xsltCompiler = processor.NewXsltCompiler(); 
             xsltCompiler.XsltLanguageVersion = "3.0"; 
             XsltPackage packageA; 
             using (Stream stream = File.OpenRead("D:/MyDownloads/mrs2/packageA.xslt")) 
                 packageA = xsltCompiler.CompilePackage(stream); 

             xsltCompiler = processor.NewXsltCompiler(); 
             xsltCompiler.XsltLanguageVersion = "3.0"; 
             xsltCompiler.ImportPackage(packageA); 
             XsltPackage packageB; 
             using (Stream stream = File.OpenRead("D:/MyDownloads/mrs2/packageB.xslt")) 
                 packageB = xsltCompiler.CompilePackage(stream); 

             xsltCompiler = processor.NewXsltCompiler(); 
             xsltCompiler.XsltLanguageVersion = "3.0"; 
             xsltCompiler.ImportPackage(packageA); 
             xsltCompiler.ImportPackage(packageB); 
             XsltExecutable exec = xsltCompiler.Compile(new Uri("file:///D:/MyDownloads/mrs2/test.xslt")); 
             XsltTransformer transf = exec.Load(); 
             Serializer serializer = new Serializer(); 
             StringWriter sw = new StringWriter(); 
             serializer.SetOutputWriter(sw); 
             serializer.SetOutputProperty(Serializer.METHOD, "text"); 
             transf.Run(serializer); 
             string res = sw.ToString(); 

 </pre> 
 After running C#, it throws exception with message: 
 java.lang.AssertionError: 'Saxon can't find the new component corresponding to function pA:helper#0' 

Back