문제

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