Domanda

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>
È stato utile?

Soluzione

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)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top