Create xslt files programmatically

北慕城南 提交于 2019-11-28 12:56:12

Since XSLT it's XML too, you can simply use the same strategy:

...
Document document = documentBuilder.newDocument();

Element rootElement = document.createElement("xsl:stylesheet");
// adding attributes like namespaces etc...

document.appendChild(rootElement); 
Element em = document.createElement("xsl:template");
em.setAttribute("match", "/");

and so on...

But it's not very elegant. You should use a library or a framework instead, you should easily find one googling around.

You can create an XSLT the same way you create an XML file, since XSLTs are XML files.

However, if you have to deal with XML/XSLT transformations a lot, Apache Cocoon 3 has a very lightweight XML/XSLT pipeline system to use as a library instead of dealing with all XML dom stuff and XSLT transformations manually.

Michael Kay

DOM is a pretty cumbersome way of creating XML.

There's a far better way - use XSLT.

The more complex the XML, the bigger the win from using XSLT rather than DOM to create it.

There's no reason why you can't use XSLT to create XSLT (there's even a special declaration xsl:namespace-alias to make it a little bit easier - searching for xsl:namespace-alias will show up examples of its use.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!