It worked I explicitly loaded Saxon TransformerFactory.

I am facing another problem now. In the same code given below Xpath can be “/BusinessMotivations/”, “/xmi:XMI/XMI.content[@template='design']” etc.

But with these Xpath it throws XPathExpressionException.


Any help on this.




From: Raj, Shailesh
Sent: Monday, November 20, 2006 9:38 AM
To: ''
Subject: 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?