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

stylesheet output method request is ignored by XSLTC with chained transformers

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 1.2.3
    • Fix Version/s: 1.2.3
    • Component/s: xml
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      1.2.3
    • CPU:
      sparc
    • OS:
      solaris_8
    • Verification:
      Verified

      Description

      Bug appears with xsltc processor and a pipeline of transformer handlers that are constructed from Templates. The following standalone programs demonstrate the bug,(Chain1.java and Chain2.java). Using the Xalan processor in jwsdp 1.2 ea
      b07 the bug does not occur. Using Xsltc in jwsdp 1.2 ea b07 the bug appears.
      The bug was found using the Astro App test mode 4; however the two standalone
      programs show the bug without need to run astro app.

      The Chain1 and Chain2 programs output should be the same for a given processor.
      In Xalans case this is true, for Xsltc it is not true. In Xsltc case the output
      is not HTML but XML. I have also tested these programs with the latest Xalan
      code from 3/25/03 cvs repository, and the bug exists in the latest xsltc as well.

      Here is the test procedure to demonstrate the problem:
      1. Install jwsdp1.2 (jwsdp-1_2-ea-bin-b07-unix-13_mar_2003.sh) jar files into
        $JAVA_HOME/jre/lib/endorsed directory.
      2. setenv JAVA_HOME /files/sqe/javas/j2sdk1.4.1_01
      3. set path = ( $JAVA_HOME/bin $path )

      Chain1 and Chain2 do the same thing, they just use a different set of JAXP
      classes to achieve the same result.

      4. javac Chain1.java
      5. javac Chain2.java

      6. Run Chain1 with Xalan and with Xsltc:
         java -cp "." Chain1 > chain1.out.xalan

         java -Djavax.xml.transform.TransformerFactory=org.apache.xalan.xsltc.trax.Tra
      nsformerFactoryImpl -cp "." Chain1 > chain1.out.xsltc

      7. Compare output from Chain1 with that of Chain2, the output should be the
         same for each of the processors.

          diff chain1.out.xalan chain2.out.xalan ... for xalan they are same

          diff chain1.out.xsltc chain2.out.xsltc ... not for xsltc

      Xsltc has the following diff:
      Warning: missing newline at end of file chain1.out.xsltc
      Warning: missing newline at end of file chain2.out.xsltc
      0a1
      > <?xml version="4.0" encoding="UTF-8"?>
      3,11c4,22
      < <b>Star Id: </b>7<br>
      < <b>Constellation: </b>Cas<br>
      < <b>Description: </b>10 Cas<br>
      < <b>RA J2000: </b>00:06:26.5<br>
      < <b>DEC J2000: </b>64:11:46<br>
      < <b>Visual Magnitude: </b>5.59<br>
      < <b>Spectral Type: </b>B9III<br>
      < <b>Galactic Longitude: </b>118.06<br>
      < <b>Galactic Latitude: </b>1.75<br><hr>
      ---
      > <b>Star Id: </b>7
      > <br/>
      > <b>Constellation: </b>Cas
      > <br/>
      > <b>Description: </b>10 Cas
      > <br/>
      > <b>RA J2000: </b>00:06:26.5
      > <br/>
      > <b>DEC J2000: </b>64:11:46
      > <br/>
      > <b>Visual Magnitude: </b>5.59
      > <br/>
      > <b>Spectral Type: </b>B9III
      > <br/>
      > <b>Galactic Longitude: </b>118.06
      > <br/>
      > <b>Galactic Latitude: </b>1.75
      > <br/>
      > <hr/>

      For xsltc processor, the final output of the chained transformers is NOT
      HTML, which it should be. The final output has the xml heading and
      <br/> elements. It appears as though the output method (set to HTML) of
      the last stylesheet (html.xsl) is not being obeyed with the xsltc processor
      while running Chain2 program.


      Below are the files needed to run the procedure:
      ==========================================
      Chain1.java:
      ------------
      mport javax.xml.parsers.*;
      import org.xml.sax.*;
      import javax.xml.transform.*;
      import javax.xml.transform.sax.*;
      import javax.xml.transform.stream.*;

      public class Chain1 {
          public static void main(String[] args){

              try {
                  // set up input stream
                  InputSource input = new InputSource("catalog.xml");

                  // set up to read the input file
                  SAXParserFactory spf = SAXParserFactory.newInstance();
                  spf.setNamespaceAware(true);
                  SAXParser parser = spf.newSAXParser();
                  XMLReader reader = parser.getXMLReader();

                  // create the filters
                  SAXTransformerFactory stf =
                      (SAXTransformerFactory)TransformerFactory.newInstance();
                  TransformerHandler filter1 = stf.newTransformerHandler(
                              new StreamSource("ra.xsl"));
                  TransformerHandler filter2 = stf.newTransformerHandler(
                              new StreamSource("html.xsl"));

                  // connect last filter to system.out
                  filter2.setResult(new StreamResult(System.out));

                  // connect the last filter to the first filter in chain
                  // filter2 is a TranformerHandler, which is-a ContentHandler
                  // which is an arg to SAXResult
                  filter1.setResult(new SAXResult(filter2));

                  // hook the output of the XMLReader to the first filter
                  reader.setContentHandler(filter1);

                  // parse the XML doc, which starts the pipeline
                  reader.parse(input);

              }
              catch (Exception e) {
                  System.err.println("Exception : " + e);
              }
          }
      }

      Chain2.java
      ------------
      import javax.xml.parsers.*;
      import org.xml.sax.*;
      import javax.xml.transform.*;
      import javax.xml.transform.sax.*;
      import javax.xml.transform.stream.*;

      public class Chain2 {
          public static void main(String[] args){

              try {
                  // set up input stream
                  InputSource input = new InputSource("catalog.xml");

                  // set up to read the input file
                  SAXParserFactory spf = SAXParserFactory.newInstance();
                  spf.setNamespaceAware(true);
                  SAXParser parser = spf.newSAXParser();
                  XMLReader reader = parser.getXMLReader();

                  // create the filters
                  SAXTransformerFactory stf =
                      (SAXTransformerFactory)TransformerFactory.newInstance();
                  TemplatesHandler tempHandlr = stf.newTemplatesHandler();
                  SAXParserFactory pfact = SAXParserFactory.newInstance();
                  pfact.setNamespaceAware(true);
                  XMLReader xsl_reader = pfact.newSAXParser().getXMLReader();
                  xsl_reader.setContentHandler(tempHandlr);
                  xsl_reader.parse(new InputSource("ra.xsl"));
                  Templates templates1 = tempHandlr.getTemplates();
                  TransformerHandler filter1 = stf.newTransformerHandler(templates1);

                  xsl_reader.parse(new InputSource("html.xsl"));
                  Templates templates2 = tempHandlr.getTemplates();
                  TransformerHandler filter2 = stf.newTransformerHandler(templates2);


                  // connect last filter to system.out
                  filter2.setResult(new StreamResult(System.out));

                  // connect the last filter to the first filter in chain
                  // filter2 is a TranformerHandler, which is-a ContentHandler
                  // which is an arg to SAXResult
                  filter1.setResult(new SAXResult(filter2));

                  // hook the output of the XMLReader to the first filter
                  reader.setContentHandler(filter1);

                  // parse the XML doc, which starts the pipeline
                  reader.parse(input);

              }
              catch (Exception e) {
                  System.err.println("Exception : " + e);
              }
          }
      }
      ---------------------------
      ra.xsl:

      <xsl:transform
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

      <xsl:output method="xml"/>

      <!-- ra between 00:00:00 and 01:00:00 -->
      <xsl:param name="ra_min_hr" select="0.106"/>
      <xsl:param name="ra_max_hr" select="0.108"/>

      <xsl:template match="stardb">
            <stardb>
            <xsl:apply-templates/>
            </stardb>
      </xsl:template>

      <xsl:template match="star">
         <xsl:if test="(
                        (number(ra/dv) >= $ra_min_hr) and
                        (number(ra/dv) <= $ra_max_hr))" >
                <xsl:copy-of select="."/>
         </xsl:if>
      </xsl:template>

      </xsl:transform>


      ------------------
      html.xsl:

      <xsl:transform
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

      <xsl:output method="html"/>


      <xsl:template match="stardb">
         <h1>Bright Star Catalog Extract</h1>
         <body>
            <xsl:apply-templates/>
         </body>
      </xsl:template>

      <xsl:template match="star">
         <b>Star Id: </b><xsl:value-of select="hr"/><br/>
         <b>Constellation: </b><xsl:value-of select="constellation"/><br/>
         <b>Description: </b><xsl:value-of select="fullname"/><br/>
         <b>RA J2000: </b><xsl:value-of select="ra/h"/><xsl:text>:</xsl:text><xsl:valu
      e-of select="ra/m"/><xsl:text>:</xsl:text><xsl:value-of select="ra/s"/><br/>
         <b>DEC J2000: </b><xsl:value-of select="ra/sgn"/><xsl:value-of select="dec/d"
      /><xsl:text>:</xsl:text><xsl:value-of select="dec/m"/><xsl:text>:</xsl:text><xsl
      :value-of select="dec/s"/><br/>
         <b>Visual Magnitude: </b><xsl:value-of select="vmag"/><br/>
         <b>Spectral Type: </b><xsl:value-of select="spec"/><br/>
         <b>Galactic Longitude: </b><xsl:value-of select="glng"/><br/>
         <b>Galactic Latitude: </b><xsl:value-of select="glat"/><br/>
         <hr></hr>
      </xsl:template>

      </xsl:transform>

      ------------------
      XML document, catalog.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <stardb><star><hr>1</hr><constellation/><fullname/><ra><h>00</h><m>05</m><s>09.9
      </s><dv>0.08608333333333333</dv></ra><dec><sgn/><d>45</d><m>13</m><s>45</s><dv>4
      5.22916666666667</dv></dec><glng>114.44</glng><glat>-16.88</glat><vmag>6.70</vma
      g><spec>A1Vn</spec></star><star><hr>2</hr><constellation/><fullname/><ra><h>00</
      h><m>05</m><s>03.8</s><dv>0.08438888888888889</dv></ra><dec><sgn>-</sgn><d>00</d
      ><m>30</m><s>11</s><dv>-0.5030555555555556</dv></dec><glng>98.33</glng><glat>-61
      .14</glat><vmag>6.29</vmag><spec>gG9</spec></star><star><hr>3</hr><constellation
      >Psc</constellation><fullname>33 Psc</fullname><ra><h>00</h><m>05</m><s>20.1<
      /s><dv>0.08891666666666666</dv></ra><dec><sgn>-</sgn><d>05</d><m>42</m><s>27</s>
      <dv>-5.7075000000000005</dv></dec><glng>93.75</glng><glat>-65.93</glat><vmag>4.6
      1</vmag><spec>K0IIIbCN-0.5</spec></star><star><hr>4</hr><constellation>Peg</cons
      tellation><fullname>86 Peg</fullname><ra><h>00</h><m>05</m><s>42.0</s><dv>0.0
      95</dv></ra><dec><sgn/><d>13</d><m>23</m><s>46</s><dv>13.39611111111111</dv></de
      c><glng>106.19</glng><glat>-47.98</glat><vmag>5.51</vmag><spec>G5III</spec></sta
      r><star><hr>5</hr><constellation/><fullname/><ra><h>00</h><m>06</m><s>16.0</s><d
      v>0.10444444444444445</dv></ra><dec><sgn/><d>58</d><m>26</m><s>12</s><dv>58.4366
      6666666666</dv></dec><glng>117.03</glng><glat>-03.92</glat><vmag>5.96</vmag><spe
      c>G5V</spec></star><star><hr>6</hr><constellation/><fullname/><ra><h>00</h><m>06
      </m><s>19.0</s><dv>0.10527777777777779</dv></ra><dec><sgn>-</sgn><d>49</d><m>04<
      /m><s>30</s><dv>-49.075</dv></dec><glng>321.61</glng><glat>-66.38</glat><vmag>5.
      70</vmag><spec>G1IV</spec></star><star><hr>7</hr><constellation>Cas</constellati
      on><fullname>10 Cas</fullname><ra><h>00</h><m>06</m><s>26.5</s><dv>0.10736111
      111111112</dv></ra><dec><sgn/><d>64</d><m>11</m><s>46</s><dv>64.19611111111111</
      dv></dec><glng>118.06</glng><glat>1.75</glat><vmag>5.59</vmag><spec>B9III</spec>
      </star><star><hr>8</hr><constellation/><fullname/><ra><h>00</h><m>06</m><s>36.8<
      /s><dv>0.11022222222222222</dv></ra><dec><sgn/><d>29</d><m>01</m><s>17</s><dv>29
      .02138888888889</dv></dec><glng>111.26</glng><glat>-32.83</glat><vmag>6.13</vmag
      ><spec>K0V</spec></star><star><hr>9</hr><constellation/><fullname/><ra><h>00</h>
      <m>06</m><s>50.1</s><dv>0.11391666666666667</dv></ra><dec><sgn>-</sgn><d>23</d><
      m>06</m><s>27</s><dv>-23.1075</dv></dec><glng>52.21</glng><glat>-79.14</glat><vm
      ag>6.18</vmag><spec>A7V</spec></star><star><hr>10</hr><constellation/><fullname/
      ><ra><h>00</h><m>07</m><s>18.2</s><dv>0.12172222222222222</dv></ra><dec><sgn>-</
      sgn><d>17</d><m>23</m><s>11</s><dv>-17.386388888888888</dv></dec><glng>74.36</gl
      ng><glat>-75.90</glat><vmag>6.19</vmag><spec>A6Vn</spec></star></stardb>


      I have attached a jar file (bug.jar) with all of these files as well.
      I ran this under j2sdk1.4.1_01 with jar files from jaxp1.2.2 installed from
      the jwsdp 1.2ea mentioned above.

      ###@###.### 2003-04-14


        Attachments

          Activity

            People

            • Assignee:
              ayadavsunw Arun Yadav (Inactive)
              Reporter:
              duke J. Duke (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: