[jdom-interest] Passing JDOM to JAXP using SAX
Robert Koberg
rob at koberg.com
Fri Apr 30 04:31:57 PDT 2004
Per Norrman wrote:
> Hi,
>
> Daniel Purucker wrote:
>
>> Hi,
>> i want to transform an jdom-document with xslt. Because i'm not able
>> to pass JDOM-Output directly to JAXP, i'm using the workaround
>> proposed by Eric Burke, to transform JDOM into SAX.
>
>
> it is not entirely clear what you want to do. But if you have
> a JDOM Document and a stylesheet to transform it, but want to produce
> SAX event from that transformation, I think something like this should
> do it:
>
> Document doc = ....
> String xsl = <style sheet URL>
>
> TransformerFactory factory = TransformerFactory.newInstance();
> Transformer t = factory.newTransformer(new StreamSource(xsl));
> SAXResult result = new SAXResult(...);
> t.transform(new JDOMSource(doc), result);
>
>
>> What's wrong?
>> the "stylesheet" has to be an instance of
>> "javax.xml.transform.Templates", but how do i create this?
>
>
> Who says it must be Templates instance? Your requirements or an error
> message?
A Templates object can be cached while a Transformer should not be
cached. So off in the cache you can do:
TransformerFactory factory = TransformerFactory.newInstance();
// perhaps set custom URIResolver for xsl:import/include
StreamSource ss = new StreamSource(new InputStream(xslPath));
Templates templates = factory.newTemplates(ss);
// put into a map or something
Then in a servlet/jsp:
Templates templates = cache.getTemplates(xslPath);
Transformer transformer = templates.newTransformer();
// perhaps set custom URIResolver for document() to
// get other JDOMSources or whatever
best,
-Rob
>
>
> /pmn
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
>
>
More information about the jdom-interest
mailing list