XSLTC: Multiple namespace prefixes produce unexpected prefixes in output
------------------------------------------------------------------------

         Key: XALANJ-2032
         URL: http://nagoya.apache.org/jira/browse/XALANJ-2032
     Project: XalanJ2
        Type: Bug
  Components: XSLTC  
    Versions: 2.6    
    Reporter: Alfred Nathaniel


The bug can be demonstrated with the following stylesheet:

<?xml version="1.0"?>
<!-- bug3.xsl -->
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:xhtml="http://www.w3.org/1999/xhtml";
  xmlns="http://www.w3.org/1999/xhtml";
  exclude-result-prefixes="xhtml"
  version="1.0">

  <xsl:template match="never">
    <xhtml:br/>
  </xsl:template>

  <xsl:template match="/">
    <html>
      <body>
        Hello<br/>world
      </body>
    </html>
  </xsl:template>

</xsl:stylesheet>

Given any input the result produced by the Xalan interpreter is:

xalan -in bug3.xsl -xsl bug3.xsl
<html xmlns="http://www.w3.org/1999/xhtml";>
  <body>
    Hello<br/>world
  </body>
</html>

XSLTC 2.6.0 produces a different output:

xalan -in in2.xml -xsl bug2.xsl -xsltc -v
>>>>>>> Xalan Version Xalan Java 2.6.0, <<<<<<<
<html xmlns="http://www.w3.org/1999/xhtml";>
  <body>
    Hello<xhtml:br xmlns:xhtml="http://www.w3.org/1999/xhtml"/>world
  </body>
</html>

As XML documents both versions are equivalent that one could argue it not 
really being a bug. However, contemporary browsers (Explorer6.0, Firebox0.9.1, 
Mozilla1.7) ignore prefixed HTML tags, that the use of XSLTC for HTML-to-HTML 
transformations is handicaped.


The problem is in org.apache.xalan.xsltc.compiler.Parser. For each namespace 
there is hashtable containing all tags in the stylesheet. In the example, 
<xhtml:br/> and <br/> map to the same hashtable entry but the prefix form of 
the first one seen by the parser is kept.

The XSLTC code generator then uses this entry everywhere irrespective of the 
prefix form used at the current position in the stylesheet. In order to avoid 
the pro blem, the hashtable entries should be normalized to use a single prefix 
form.

WORKAROUNDS

The safest way to avoid the problem is to avoid using multiple prefixes for the 
same namespace. Note that with an appropriate <xls:import> sequence also 
<xsl:template match="xhtml:br"> without any literal <xhtml:br/> can lead to the 
same effect. That means for XHTML-to-XHTML transformations that all literal 
tags in the stylesheet must use the prefixed notation (<xhtml:html>).

If that is too tedious for stylesheets containing a lot of literal HTML tags, 
you have to rearrange the imports and template definitions that the parser sees 
for all tags the non-prefixed form first. Otherwise we will have to filter the 
XSLTC output to do the prefix normalization in a separate step.


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://nagoya.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to