It would be fairly straightforward to add a addProcessingInstruction(target, value) API to the Document interface. Or, if we want to be a bit more specific, addStylesheet(href).
- James Garrett Rooney wrote: > On 8/6/06, James M Snell <[EMAIL PROTECTED]> wrote: >> Danny, >> >> There are two things you could do here. >> >> 1. Drop down to the Axiom APIs to add the PI (so the browser can apply >> the transform) >> >> Factory factory = Factory.INSTANCE; >> Document<Feed> doc = factory.newDocument(); >> >> // drop down to the Axiom interfaces >> OMFactory omfactory = (OMFactory) factory; >> omfactory.createOMProcessingInstruction( >> (OMContainer)doc, >> "xml-stylesheet", >> "href=\"foo.xslt\""); >> >> // then create the root element >> factory.newFeed(doc); >> >> doc.writeTo(System.out); >> >> yields: >> >> <?xml version='1.0' encoding='UTF-8'?> >> <?xml-stylesheet href="foo.xslt"?> >> <a:feed xmlns:a="http://www.w3.org/2005/Atom"/> >> >> 2. Apply the XSLT transform on the server. You can apply XSLT >> transforms directly to the Abdera objects. >> >> TransformerFactory factory = TransformerFactory.newInstance(); >> >> // Prepare the XSLT >> Document xslt = Parser.INSTANCE.parse( >> XsltExample.class.getResourceAsStream("/test.xslt")); >> AbderaSource xsltSource = new AbderaSource(xslt); >> Transformer transformer = factory.newTransformer(xsltSource); >> >> // Now let's get the feed we're going to transform >> Document<Feed> feed = Parser.INSTANCE.parse( >> XsltExample.class.getResourceAsStream("/simple.xml")); >> AbderaSource feedSource = new AbderaSource(feed); >> >> // Transform and output >> ByteArrayOutputStream out = new ByteArrayOutputStream(); >> Result result = new StreamResult(out); >> transformer.transform(feedSource, result); >> System.out.println(out); > > Should we consider adding some non-axiom-specific way to do this sort > of thing? Stylesheets are becoming more and more common in feeds, and > it would be nice to be able to portably add one to a feed generated by > Abdera. Doing so via XSLT seems like an interesting work around, but > perhaps we should consider adding support for this to the core of the > system. > > -garrett >
