Uploaded image for project: 'XalanJ2'
  1. XalanJ2
  2. XALANJ-2032

XSLTC: Multiple namespace prefixes produce unexpected prefixes in output

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.7.1, 2.7, 2.6
    • None
    • XSLTC
    • None
    • fp2

    Description

      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 bug3.xsl -xsl bug3.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.

      Attachments

        1. bug3.xsl
          0.4 kB
          Alfred Nathaniel

        Issue Links

          Activity

            People

              santiago.pericasgeertsen@sun.com Santiago Pericas-Geertsen
              anathaniel@apache.org Alfred Nathaniel
              Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: