You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by bu...@apache.org on 2001/04/19 16:40:43 UTC

[Bug 1397] New - apply-imports shouldn't invoke built-ins to process children

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1397

*** shadow/1397	Thu Apr 19 07:40:42 2001
--- shadow/1397.tmp.28624	Thu Apr 19 07:40:43 2001
***************
*** 0 ****
--- 1,231 ----
+ +============================================================================+
+ | apply-imports shouldn't invoke built-ins to process children               |
+ +----------------------------------------------------------------------------+
+ |        Bug #: 1397                        Product: XalanJ2                 |
+ |       Status: NEW                         Version: 2.0.0                   |
+ |   Resolution:                            Platform: Sun                     |
+ |     Severity: Normal                   OS/Version: Solaris                 |
+ |     Priority: Medium                    Component: org.apache.xalan.xsltc  |
+ +----------------------------------------------------------------------------+
+ |  Assigned To: xalan-dev@xml.apache.org                                     |
+ |  Reported By: tamiro@east.sun.com                                          |
+ |      CC list: Cc:                                                          |
+ +----------------------------------------------------------------------------+
+ |          URL:                                                              |
+ +============================================================================+
+ |                              DESCRIPTION                                   |
+ [from SunMicrosystem's bug 4404012]
+ 
+ <xsl:apply-imports> should not act like apply-templates and invoke
+ the built-in rules to process all children of the current node.
+ 
+ The following test illustrates problems with the way xsltc implements
+ apply-imports. 
+ 
+ The source doc is:
+ 
+ <doc>
+ <title>Testing:import-precedence</title>
+ <author>Joe Jones</author>
+ <overview>testing-import</overview>
+ <chapters>
+ <chapter num="1">know xsl</chapter>
+ <chapter num="2">love xsl</chapter>
+ </chapters>
+ </doc>
+ 
+ The main style sheet is:
+ 
+ <?xml version="1.0"?> 
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+ 
+ <xsl:import href="./inc/b.xsl"/>
+ <xsl:import href="./inc/c.xsl"/>
+ 
+ <xsl:template match="/">
+   <out>
+     <xsl:apply-templates/>
+   </out>
+ </xsl:template>
+  
+ <xsl:template match="title">
+   Import01-title<xsl:text>,</xsl:text>
+   <xsl:apply-imports/>
+ </xsl:template>
+ 
+ </xsl:stylesheet>
+ 
+ The imported style sheets are:
+ 
+ c.xsl
+ -----
+ <?xml version="1.0"?> 
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+ <xsl:import href="e.xsl"/>
+ 
+ <xsl:template match="title">
+   C-title:<xsl:text>,</xsl:text>
+   <xsl:apply-imports/>
+ </xsl:template>
+   
+ <xsl:template match="chapters">
+   C-chapters:
+   <xsl:apply-imports/>
+ </xsl:template>   
+ </xsl:stylesheet>
+  
+ d.xsl
+ -----
+ <?xml version="1.0"?> 
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+ 
+ <xsl:template match="title">
+   D-title:
+ </xsl:template> 
+ 
+ <xsl:template match="overview">
+   D-overview: 
+   <xsl:value-of select="."/>
+ </xsl:template>
+    
+ </xsl:stylesheet>
+ e.xsl
+ -----
+ <?xml version="1.0"?> 
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+ 
+ <xsl:template match="title">
+   E-title:<xsl:text>,</xsl:text>
+ </xsl:template>
+ 
+ <xsl:template match="chapter">
+   E-chapter: 
+   <xsl:value-of select="@num"/><xsl:text>.</xsl:text>  
+   <xsl:value-of select="."/>
+ </xsl:template> 
+    
+ </xsl:stylesheet>
+ 
+ Norm Walsh looked at this and agreed. 
+ The Saxon output is correct:
+ 
+ Expected Output (Saxon)
+ -----------------------
+ <?xml version="1.0" encoding="utf-8"?><out>
+ 
+   Import01-title,
+   C-title:,
+   E-title:,
+ 
+   B-author:  
+   ,
+ 
+   D-overview: 
+   testing-import
+ 
+   C-chapters:
+   
+ </out> 
+ 
+ Actual output from xsltc
+ ------------------------
+ 
+ <?xml version="1.0" encoding="utf-8" ?>
+ <out>
+ 
+   Import01-title,Testing:import-precedence
+ 
+   B-author:  
+   Joe Jones,
+ 
+   D-overview: 
+   testing-import
+ 
+   C-chapters:
+   
+ 
+   E-chapter: 
+   1.know xsl
+ 
+   E-chapter: 
+   2.love xsl
+ 
+ </out>
+ 
+ This is hard to explain. Let me try walking through it.
+ 
+ 1. In main xsl, apply-templates in the template matching /,
+    finds the template matching "title" in the main xsl
+    and outputs
+ 
+ 	Import-title,
+ 
+ 2. The the apply-imports looks for a template matching 
+    "title" in the imported xsls and finds the one in c.xsl 
+     first and outputs the following as a result
+ 
+ 	C-title:,
+ 
+ 3.  The apply-imports in the current "title" template
+     looks for a template matching "title" in an 
+     imported xsl, finds one in e.xsl and outputs
+ 
+ 	E-title:,
+ 
+ 4. Processing returns to the apply-templates in the main xsl,
+    which goes to the next child of /, <author>. It finds
+    a matching template in b.xsl first and as a result outputs
+ 
+ 	B-author:
+ 	,
+ 
+ 5. Then the apply-imports looks for another template matching
+    <author> in an imported xsl and find none, so control returns
+    to the main apply-templates which goes on to <overview>. 
+    A matching template is found in d.xsl and outputs
+ 
+ 	D-overview: testing-import
+ 
+ 6. Back to apply-templates in main xsl, it goes on to <chapters>
+    finding the matching template in c.xsl and outputs
+ 
+ 	C-chapters:
+ 
+ 7. The apply-imports does not find any other template 
+    matching on "chapters" in any imported xsl, so control
+    returns to the main apply-templates, which has run out 
+    of children of the root element to process. 
+ 
+ Note: processing never gets to the <chapter> elements
+ because they are children of <chapters>. 
+ 
+ The following template in c.xsl
+ 
+ <xsl:template match="chapters">
+   C-chapters
+   <xsl:apply-imports/>
+ </xsl:template>
+ 
+ is the only template in any of the 
+ style sheets that match the "chapters"
+ element. There are no other templates that 
+ match the <chapters> element. So the 
+ <apply-imports> in the template matching 
+ the "chapter" element should have no 
+ effect. The <chapters> children of 
+ <chapter> should never get processed.
+ 
+ If the template in c.xsl matching on "chapters" had apply-templates, 
+ rather than apply-imports, the contents of the <chapter> 
+ elments would and should have been ouput.
+  
+ It looks like xsltc invoked the template in e.xsl 
+ that matches the <chapter> element. That template should 
+ not have be invoked by the <apply-imports/>
+ instruction in the template matching the "chapters" 
+ element in style sheet c.xsl. And there was no 
+ other way to get to it.  
+ 
+ <apply-imports> should not act like apply-templates and invoke
+ the built-in rules to process all children of the
+ current node.