我有一個包含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