You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by bu...@apache.org on 2001/04/16 22:25:57 UTC
[Bug 1348] New - Xalan doesn't work properly when the qName parameter in SAX2 is empty
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1348
*** shadow/1348 Mon Apr 16 13:25:57 2001
--- shadow/1348.tmp.7386 Mon Apr 16 13:25:57 2001
***************
*** 0 ****
--- 1,166 ----
+ +============================================================================+
+ | Xalan doesn't work properly when the qName parameter in SAX2 is empty |
+ +----------------------------------------------------------------------------+
+ | Bug #: 1348 Product: XalanJ2 |
+ | Status: NEW Version: 2.0.1 |
+ | Resolution: Platform: All |
+ | Severity: Normal OS/Version: All |
+ | Priority: Component: Xalan |
+ +----------------------------------------------------------------------------+
+ | Assigned To: xalan-dev@xml.apache.org |
+ | Reported By: mikael.staldal@home.se |
+ | CC list: Cc: |
+ +----------------------------------------------------------------------------+
+ | URL: |
+ +============================================================================+
+ | DESCRIPTION |
+ I'm using programatically generated SAX input to Xalan. Xalan doesn't
+ seem to work properly when the qName paramterer to the ContentHandler
+ methods is the empty string. I think that Xalan should work properly
+ even when the qName is not given.
+
+
+ Here is a test program and a stylesheet:
+
+
+ // DirTest.java
+
+
+ import java.io.*;
+
+
+ import org.xml.sax.*;
+ import org.xml.sax.helpers.AttributesImpl;
+
+
+ import javax.xml.transform.*;
+ import javax.xml.transform.Source;
+ import javax.xml.transform.sax.*;
+ import javax.xml.transform.stream.StreamSource;
+
+
+ import org.apache.xml.serialize.*;
+
+
+ public class DirTest
+ {
+ public static void main(String[] args) throws Exception
+ {
+ if (args.length < 3)
+ {
+ System.out.println("Syntax: DirTest <input_dir> <stylesheet> <output>");
+ return;
+ }
+
+
+ String inDir = args[0];
+ String xslFile = args[1];
+ String outFile = args[2];
+
+
+ TransformerFactory tf = TransformerFactory.newInstance();
+ if (!(tf.getFeature(SAXTransformerFactory.FEATURE)
+ && tf.getFeature(SAXResult.FEATURE)
+ && tf.getFeature(StreamSource.FEATURE)))
+ {
+ System.out.println("The transformer factory "
+ + tf.getClass().getName() + " doesn't support SAX");
+ return;
+ }
+ SAXTransformerFactory tfactory = (SAXTransformerFactory)tf;
+
+
+ System.out.println("Read stylesheet " + xslFile);
+
+
+ Templates stylesheet = tfactory.newTemplates(new StreamSource(xslFile));
+
+
+ System.out.println("Transforming " + inDir + " to " + outFile);
+
+
+ XMLSerializer ser = new XMLSerializer(
+ new FileOutputStream(outFile), new OutputFormat());
+
+
+ TransformerHandler th = tfactory.newTransformerHandler(stylesheet);
+ th.setResult(new SAXResult(ser.asContentHandler()));
+
+
+ generateDirListing(new File(inDir), th);
+
+
+ System.out.println("Finished");
+ }
+
+
+ static void generateDirListing(File dir, ContentHandler sax)
+ throws SAXException
+ {
+ String[] files = dir.list();
+
+
+ sax.startDocument();
+
+
+ sax.startElement("", "dirlist", "", new AttributesImpl());
+ // sax.startElement("", "dirlist", "dirlist", new AttributesImpl());
+
+
+ for (int i = 0; i < files.length; i++)
+ {
+ File file = new File(dir, files[i]);
+
+
+ AttributesImpl atts = new AttributesImpl();
+ atts.addAttribute("", "filename", "", "CDATA", files[i]);
+ // atts.addAttribute("", "filename", "filename", "CDATA", files[i]);
+
+
+ if (file.isFile())
+ {
+ sax.startElement("", "file", "", atts);
+ // sax.startElement("", "file", "file", atts);
+ sax.endElement("", "file", "");
+ // sax.endElement("", "file", "file");
+ }
+ else if (file.isDirectory())
+ {
+ sax.startElement("", "directory", "", atts);
+ // sax.startElement("", "directory", "directory", atts);
+ sax.endElement("", "directory", "");
+ // sax.endElement("", "directory", "directory");
+ }
+ else
+ ;
+ }
+
+
+ sax.endElement("", "dirlist", "");
+ // sax.endElement("", "dirlist", "dirlist");
+
+
+ sax.endDocument();
+ }
+ }
+
+
+
+ <?xml version="1.0" encoding="iso-8859-1"?>
+
+
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="1.0">
+
+
+ <xsl:template match="/">
+ Directory listing
+ </xsl:template>
+
+
+ <xsl:template match="file">
+ <li><xsl:value-of select="@filename"/></li>
+ </xsl:template>
+
+
+ </xsl:stylesheet>