Re: [xsl] SAX Transformation: Servlet returns blank XSL template

Subject: Re: [xsl] SAX Transformation: Servlet returns blank XSL template
From: "Bruce McDougald" <bmcdougald@xxxxxxxxxxx>
Date: Wed, 9 Oct 2002 16:30:07 -0500
> There's a bug in your servlet code, but without seeing the code, I can't
> begin to guess what it is.
>

Sorry, here is my code.
------------------------------------

public class pipeline extends HttpServlet{

    public void doGet (HttpServletRequest req, HttpServletResponse res)
                     throws ServletException,IOException
    {
    // Set content type for HTML.
     res.setContentType("text/html; charset=UTF-8");

     OutputStream os = res.getOutputStream();

  try{

    TransformerFactory tFactory = TransformerFactory.newInstance();

    if (tFactory.getFeature(SAXSource.FEATURE) &&
tFactory.getFeature(SAXResult.FEATURE))
    {

      XMLReader reader = XMLReaderFactory.createXMLReader();

      SAXTransformerFactory saxTFactory = ((SAXTransformerFactory)
tFactory);

      XMLFilter xmlFilter1 = new SAXParse();

      xmlFilter1.setParent(reader);

      XMLFilter xmlFilter2 =
               saxTFactory.newXMLFilter(new
StreamSource("http://localhost/taymac.nsf/dynitmact.xsl";));

      // xmlFilter1 uses the XMLReader as its reader.
      xmlFilter2.setParent(xmlFilter1);

      // xmlFilter2 outputs SAX events to the serializer.
      Serializer serializer = SerializerFactory.getSerializer

(OutputProperties.getDefaultMethodProperties("xml"));

      serializer.setOutputStream(os);

      xmlFilter2.setContentHandler(serializer.asContentHandler());
      xmlFilter2.parse(new
InputSource("http://localhost/cgi-bin/xmlbldr.pl";));

      os.flush();
      os.close();
    }

  }catch (Exception e){
    e.printStackTrace();
  }
 }
}

//////////////////////////////////////////////////////////////

public class SAXParse extends XMLFilterImpl
{

    String col;
    String row;
    String drvr;
    String root;
    String node;

    static boolean  rootFlag = false;
    static boolean  drvrFlag = false;
    static boolean  colFlag = false;
    static boolean  rowFlag = false;

    static int drvrCount = 0;
    static int colCount = 0;
    static int rowCount = 0;

    static int colStart = 85;
    static int rowStart = 0;

    static int colLimit = 13;
    static int rowLimit = 25;
    static int drvrLimit = 3;


    ////////////////////////////////////////////////////////////////////
    // Event handlers.
    ////////////////////////////////////////////////////////////////////

    public void startElement (String uri, String name,
         String qName, Attributes atts)
                              throws SAXException
    {
       boolean printIt = false;
        node = qName;

        if ( qName.equals( "ITMACT" ) ) {
             rootFlag = true;
             rowFlag = false;
             colFlag = false;
             drvrFlag = false;
             root = qName;
             printIt = true;
       }

        if ( qName.equals( "DRIVER" ) ) {
             drvrCount++;
             rowCount=0;
             rowFlag = false;
             colFlag = false;
             if (drvrCount == drvrLimit){
                drvrFlag = true;
                drvr = qName;
                printIt = true;
             }else{
                 drvrFlag = false;
             }
        }

        if ( drvrFlag && qName.equals("DRVRKEY") )  {
              printIt = true;
       }

        if (qName.equals("ROW") && drvrFlag){
           rowCount++;
           colCount = 0;
           colFlag = false;
           if ((rowCount >= rowStart) &&
               (rowCount <= rowStart + rowLimit)){
                rowFlag = true;
                row = qName;
                printIt = true;
             }else{
               rowFlag = false;
             }

        }

        if ( qName.equals("ROWKEY") && rowFlag ) {
                printIt = true;
          }

        if (qName.equals("COLUMN") && rowFlag){
           colCount++;
           if ((colCount >= colStart) &&
               (colCount <= colStart + colLimit)){
                colFlag = true;
                col = qName;
                printIt = true;
           }else{
               colFlag = false;
           }
        }

        if (( (qName.equals("COLKEY")) ||
              (qName.equals("CDATA1")) ||
              (qName.equals("CDATA2")) ||
              (qName.equals("CDATA3")) ) && colFlag ) {
              printIt = true;
        }

        if (printIt){
          super.startElement(uri,name,qName,atts);
          printIt = false;
        }

    }


    public void endElement (String uri, String name, String qName)
       throws SAXException
    {

       boolean printIt = false;

       if ( qName.equals("ITMACT") ) {
              printIt = true;
       }

       if ( drvrFlag && ( (qName.equals("DRIVER"))||
(qName.equals("DRVRKEY")) )) {
           printIt = true;
       }

        if ( ((qName.equals("ROW")) || (qName.equals("ROWKEY"))) &&
rowFlag ) {
              printIt = true;
          }

        if (( (qName.equals("COLUMN")) ||
              (qName.equals("COLKEY")) ||
              (qName.equals("CDATA1")) ||
              (qName.equals("CDATA2")) ||
              (qName.equals("CDATA3"))) && colFlag ) {
              printIt = true;
       }

        if (printIt){
          super.endElement(uri,name,qName);
          printIt = false;
        }

    }


    public void characters (char[] ch, int start, int length)
    throws SAXException
    {
        boolean wFlag = false;

        if(drvrFlag && ( node.equals("DRIVER") || node.equals("DRVRKEY")))
{ wFlag = true;};

        if(rowFlag && ( node.equals("ROW") || node.equals("ROWKEY"))) {wFlag
= true;};

        if(colFlag){ wFlag=true; }


        if(wFlag) { super.characters (ch, start, length); }
  }
  }

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread