Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6193850

XSLT processor of J2SE5.0 does't work for multiple xsl:output properties although it works on 1.4.2

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b04
    • CPU:
      x86
    • OS:
      windows_xp
    • Verification:
      Verified

      Description


      XSLT processor of J2SE5.0 does not work for multiple xsl:output properties
      although it works on 1.4.2.

      The following is a quote from XSL Transformations (XSLT) Version 1.0
       W3C Recommendation 16 November 1999.

      === Quote =================================================
      A stylesheet may contain multiple xsl:output elements and may include or
      import stylesheets that also contain xsl:output elements. All the xsl:output
      elements occurring in a stylesheet are merged into a single effective
      xsl:output element. For the cdata-section-elements attribute, the effective
      value is the union of the specified values.
      ============================================================================

      The following is a test case:

      ****************************************************************************
      (1) Create the following four files with the following contents.

      === Stylesheet.java ============================
      import javax.xml.parsers.*;
      import javax.xml.transform.*;
      import javax.xml.transform.stream.*;

      public class Stylesheet {
        public static void main (String[] args) throws Exception {
          if (args.length != 2) {
            System.exit (1);
          }

          Source source = new StreamSource (args[0]);
          Source stylesheet = new StreamSource (args[1]);
          Result result = new StreamResult (System.out);

          TransformerFactory f = TransformerFactory.newInstance();
          Transformer t = f.newTransformer (stylesheet);

          t.transform (source, result);
        }
      }

      === input.xml ============================
      <?xml version="1.0" encoding="UTF-8"?>
      <html>
        <head>
          <title>test</title>
          <script type="text/javascript">
            var n = 0;
          </script>
          <style type="text/css">
            body { }
          </style>
        </head>
        <body>
          <p>test document</p>
        </body>
      </html>

      === stylesheet-1.xsl ============================
      <?xml version="1.0" encoding="UTF-8"?>
      <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
              version="1.0">
        <xsl:output
                method="xml"
                encoding="Shift_JIS"
                omit-xml-declaration="no"
                doctype-public="-//W3C//DTD XHTML 1.1//EN"
                doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
                cdata-section-elements="script style"
                indent="yes" />

        <xsl:template match="@*|node()">
          <xsl:copy>
            <xsl:apply-templates select="@*|node()" />
          </xsl:copy>
        </xsl:template>
      </xsl:stylesheet>

      === stylesheet-N.xsl ============================
      <?xml version="1.0" encoding="UTF-8"?>
      <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
              version="1.0">
        <xsl:output method="xml" />
        <xsl:output encoding="Shift_JIS" />
        <xsl:output omit-xml-declaration="no" />
        <xsl:output doctype-public="-//W3C//DTD XHTML 1.1//EN" />
        <xsl:output doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" />
        <xsl:output cdata-section-elements="script" />
        <xsl:output cdata-section-elements="style" />
        <xsl:output indent="yes" />

        <xsl:template match="@*|node()">
          <xsl:copy>
            <xsl:apply-templates select="@*|node()" />
          </xsl:copy>
        </xsl:template>
      </xsl:stylesheet>
      ==================================================

      (2) Compile Stylesheet.java

      (3) Run java bytecode generated in (2) on J2SE5.0.
          And compare outputs generated from stylesheet-1.xsl and stylesheet-N.xsl.
          (Ex. cdata-section-elements does not work for script and style with
           stylesheet-N.xsl although they work with stylesheet-1.xsl)

      %java -version
      java version "1.5.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
      Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)
      %java Stylesheet input.xml stylesheet-1.xsl
      <?xml version="1.0" encoding="Shift_JIS"?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
      <html>
        <head>
          <title>test</title>
          <script type="text/javascript"><![CDATA[
            var n = 0;
          ]]></script>
          <style type="text/css"><![CDATA[
            body { }
          ]]></style>
        </head>
        <body>
          <p>test document</p>
        </body>
      </html>
      %java Stylesheet input.xml stylesheet-N.xsl
      <html>
        
      <head>
      <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
          
      <title>test</title>
          
      <script type="text/javascript">
            var n = 0;
          </script>
          
      <style type="text/css">
            body { }
          </style>
        
      </head>
        
      <body>
          
      <p>test document</p>
        
      </body>

      </html>
      ****************************************************************************

      ###@###.### 2004-11-11 07:40:18 GMT

        Attachments

          Activity

            People

            Assignee:
            nbajajsunw Neeraj Bajaj (Inactive)
            Reporter:
            eijsuzuk Eiji Suzuki (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: