I have a REST service implemented in GlassFish using Jersey. I have the service working using JSON output, now I would like to provide some human readable output as well. The most important thing missing in the JSON output is I want some fields in the statistics to be transformed to a clickable links, which would display a related statistics (using anoother REST call).
As I want to keep formatting and content separate, I do not want to produce HTML directly. I though using xml + xslt might be a sensible approach. I can use org.w3c.dom to produce a XML document, but I see no way how to attach a xslt to it.
Here is approximately what I do now:
@GET
@Path("history_id")
@Produces("application/xml")
public Document history(@QueryParam("id") String idText) throws ParserConfigurationException
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = factory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element root = doc.createElement("root");
doc.appendChild(root);
Element el = doc.createElement(name);
el.setTextContent(value);
root.appendChild(el);
return doc;
I would like following directive to appear in the XML produced:
<?xml-stylesheet type="text/xsl" href="history.xsl"?">
How can I specify a xslt to be attached to the XML? Or is my approach perhaps fundamentally wrong and this is usually done in some other way?