The problem is that the TransformerFactory you've instantiated is the Xalan one rather than the Saxon one. You need to set the system property javax.xml.transform.TransformerFactory to "net.sf.saxon.TransformerFactoryImpl" to get the Saxon implementation loaded.
Michael Kay

From: [] On Behalf Of Raj, Shailesh
Sent: 20 November 2006 04:08
Subject: [saxon] Xapth Query

Dear All,

I want to write one program which evaluates Xpath using SAX parser. For that I am using Xpath engine implemented by Saxon.

I want to value of Xpath with node name information not only node value. To get node name I am using transformer. This is following code.

XPathFactory xpf = XPathFactory.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON);

        XPath xpe = xpf.newXPath();

        System.err.println("Loaded XPath Provider " + xpe.getClass().getName());


        InputSource is = new InputSource(new File(filename).toURL().toString());

        SAXSource ss = new SAXSource(is);

        NodeInfo doc = ((XPathEvaluator)xpe).setSource(ss);


        XPathExpression findLine = xpe.compile(xpath);


        TransformerFactory f = TransformerFactory.newInstance();

        Transformer t = f.newTransformer();


        NodeInfo node = (NodeInfo)findLine.evaluate(doc, XPathConstants.NODE);

        StringWriter sw = new StringWriter();


        t.transform(node, new StreamResult(sw));


        String result = sw.toString();



But this code is giving following exception

javax.xml.transform.TransformerException: Can't transform a Source of type net.sf.saxon.tinytree.TinyDocumentImpl

      at org.apache.xalan.transformer.TransformerIdentityImpl.transform(



Anybody can let me know what is wrong with code or approach?