users@jersey.java.net

Marshaling JAXB objects including stylesheet information

From: Christopher Piggott <cpiggott_at_gmail.com>
Date: Thu, 5 Mar 2009 09:35:25 -0500

I'd like to be able to include an xml-stylesheet processing
instruction in the xml output from my jersey resources. I figured out
a way to accomplish this whereby I do the marshalling myself:

        /* xslPath is passed in as a URI */
        w.write("<?xml version=\"1.0\" encoding=\""
                + marshaller.getProperty(Marshaller.JAXB_ENCODING)
                + "\"?>\n");
        w.write("<?xml-stylesheet type=\"text/xsl\""
                + " href=\""
                + xslPath.toASCIIString()
                + "\"?>\n");
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
        marshaller.marshal(item, w);

but this is pretty ugly stuff.

Anybody have a better idea?

--Chris