Tôi có dự án Java maven bao gồm các phép biến đổi XSLT. Tôi tải biểu định kiểu như sau:Chuyển đổi Không do 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);
Biểu định kiểu.xsl có một số câu lệnh. Những dường như đang gây ra vấn đề, khi tôi cố gắng chạy thử nghiệm đơn vị của tôi tôi nhận được các lỗi sau đây:
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
Các bao gồm báo cáo trong XSLT là các liên kết tương đối
xsl:include href="footer.xsl"
xsl:include href="topbar.xsl"
Tôi đã cố gắng thử nghiệm và thay đổi những điều sau đây - nhưng tôi vẫn gặp lỗi.
xsl:include href="xsl/footer.xsl"
xsl:include href="xsl/topbar.xsl"
Bất kỳ ý tưởng nào? Bất kỳ giúp đỡ nhiều đánh giá cao.
Đừng quên đặt 'documentBuilderFactory.setNamespaceAware (true)'. Không làm như vậy có thể ngăn chặn biểu định kiểu cha mẹ tải bất kỳ mẫu nào trong biểu định kiểu con của bạn, dẫn đến lỗi ElemTemplateElement. –
Hãy cẩn thận, setURIResolver cũng có thể được đặt trên máy biến áp (tức là thay vì nhà máy), nhưng nó không có tác dụng sau đó. – robert