2 Replies Latest reply on Feb 26, 2003 6:28 PM by markcharles

    Do I have a parser config problem?

    markcharles

      Greetings,
      I'm using the Jboss-3.0.3_tomcat-4.1.12 bundle. I'm trying to do an XSL translation in a servlet. I have my .xsl file in the .war. I build my xml document from scratch. When I do:

      InputStream xslFile = getServletConfig().getServletContext().getResourceAsStream("/joblist_html.xsl");
      TransformerFactory tf = TransformerFactory.newInstance();
      Transformer t = tf.newTransformer(new StreamSource(xslFile));

      It throws a TransformerException: stylesheet requires attribute: version. I know my .xsl file has a version="1.0" in both the <?xml and <?xsl:stylesheet elements.

      Someone wrote that most likely my xml parser strips all the namespace info from the parsed documents. And when the xsl processor tries to interpret the xsl document, it does not find a correct xsl:stylesheet element. How do I tell whatever xml parser the Transformer class is using that setNameSpaceAware(true)? Is it a tomcat or jboss configuration setting somewhere, or does anyone think I have another problem?

      Thanks a bunch.
      MCharles

        • 1. Re: Do I have a parser config problem?
          markcharles

          Well, there was no config problem. I decided to try parsing the .xsl file into a DOM tree, then pass the DOM object to the Transformer like this:

          InputStream xslFile=getServletConfig().getServletContext().getResourceAsStream("/joblist_html.xsl");
          Document xslDoc = null;
          try {
          dbf=DocumentBuilderFactory.newInstance();
          dbf.setNamespaceAware(true);
          DocumentBuilder db=dbf.newDocumentBuilder();
          xslDoc = db.parse(xslFile);
          }
          TransformerFactory tf=TransformerFactory.newInstance();
          try {
          Transformer t = tf.newTransformer(new DOMSource(xslDoc));
          t.transform(new DOMSource(xmlDoc),new StreamResult(out));
          }

          MCharles

          • 2. Re: Do I have a parser config problem?
            markcharles

            Well, there was no config problem. I decided to try parsing the .xsl file into a DOM tree, then pass the DOM object to the Transformer like this:

            InputStream xslFile=getServletConfig().getServletContext().getResourceAsStream("/joblist_html.xsl");
            Document xslDoc = null;
            try {
            dbf=DocumentBuilderFactory.newInstance();
            dbf.setNamespaceAware(true);
            DocumentBuilder db=dbf.newDocumentBuilder();
            xslDoc = db.parse(xslFile);
            }
            TransformerFactory tf=TransformerFactory.newInstance();
            try {
            Transformer t = tf.newTransformer(new DOMSource(xslDoc));
            t.transform(new DOMSource(xmlDoc),new StreamResult(out));
            }

            MCharles