[jdom-interest] JDOM and XSL
    Jan Peter Hecking 
    jan at netgaroo.com
       
    Wed Feb  7 12:54:47 PST 2001
    
    
  
On Wed, Feb 07, 2001 at 12:54:03AM -0800, Charlie Wu wrote:
> I tried to play with your code with some minor alterations .. and I believe
> I am using the latest xalan-j(2.0) and xerces.jar.. however when I tried to
> run my program I'm getting this error (in debugger, if I run it directly it
> hangs).. any ideas?
> 
> javax.xml.transform.TransformerException: Namespace not supported by
> SAXParser
Sorry I have no idea why you get this exception.
But may I ask why you use JDOM at all? If you are starting with a
XML file and want to get another XML file there's no reason to
convert either source or result to JDOM first.
What you do right now looks something like this:
            Stylesheet
                V
XML -> JDOM -> XSLT -> JDOM -> XML
But realy you want this:
            Stylesheet
                V
        XML -> XSLT -> XML
Take a look at the attached XML2HTML.java. It's a lot simpler - and
it works! ;-)
bye,
Jan
-- 
Jan Peter Hecking                  jhecking at netgaroo.com
University of Rostock     Department of Computer Science
Homepage: http://www.informatik.uni-rostock.de/~jhecking
-------------- next part --------------
// Xalan-J 2
import javax.xml.transform.*;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import java.io.File;
class XML2HTML {
    public void transform(String xmlFile, String xslFile) 
        throws Exception
    {
        TransformerFactory transformerFactory =
            TransformerFactory.newInstance();
        Templates stylesheet = transformerFactory.newTemplates(
                new StreamSource( new File( xslFile ) ) );
        Transformer processor = stylesheet.newTransformer();
        StreamSource source = new StreamSource( new File( xmlFile ) );
        StreamResult result = new StreamResult( System.out );
        processor.transform( source, result );
    }
    public static void main(String[] args) throws Exception
    {
        XML2HTML x2h = new XML2HTML();
        x2h.transform("su.xml", "su.xsl");
    }
}
    
    
More information about the jdom-interest
mailing list