Suppose you have built your XML document using JDOM2 library. What is the API for adding xml-stylesheet to get something like:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<root>
  <node>
...
</root>
有帮助吗?

解决方案

I was fishing around for a while before I found the proper method call. So here it is in case someone is looking as well:

Document doc = ...

Map<String, String> m = new HashMap<String, String>(); 
m.put("href", "test.xsl"); 
m.put("type", "text/xsl"); 
doc.addContent(0, new ProcessingInstruction("xml-stylesheet", m)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top