我有一个包含XSLT转换的Java Maven项目。我加载样式表如下:转换由于xsl失败:include
TransformerFactory tFactory = TransformerFactory.newInstance();
DocumentBuilderFactory dFactory = DocumentBuilderFactory
.newInstance();
dFactory.setNamespaceAware(true);
DocumentBuilder dBuilder = dFactory.newDocumentBuilder();
ClassLoader cl = this.getClass().getClassLoader();
java.io.InputStream in = cl.getResourceAsStream("xsl/stylesheet.xsl");
InputSource xslInputSource = new InputSource(in);
Document xslDoc = dBuilder.parse(xslInputSource);
DOMSource xslDomSource = new DOMSource(xslDoc);
Transformer transformer = tFactory.newTransformer(xslDomSource);
stylesheet.xsl有一些语句。这些似乎引起问题,当我尝试运行我的单元测试,我得到以下错误:
C:\Code\workspace\app\dummy.xsl; Line #0; Column #0; Had IO Exception with stylesheet file: footer.xsl
C:\Code\workspace\app\dummy.xsl; Line #0; Column #0; Had IO Exception with stylesheet file: topbar.xsl
中的包括XSLT语句是相对链接
xsl:include href="footer.xsl"
xsl:include href="topbar.xsl"
我试图尝试和改变这些以下 - 但我仍然得到错误。
xsl:include href="xsl/footer.xsl"
xsl:include href="xsl/topbar.xsl"
任何想法?任何帮助非常感谢。
不要忘记设置`documentBuilderFactory.setNamespaceAware(true)`。否则可能会阻止父样式表加载子样式表中的任何模板,从而导致ElemTemplateElement错误。 – 2014-01-31 16:53:01