我的 XSL-FO 转换不适用于下面指定的 XML。似乎那些 xmlns 和 schemaLocation 正在困扰转换。
<book
xmlns="http://www.example.org/book"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/book book.xsd">
<title>Something</title>
</book>
但是,如果我像下面这样重写我的 XML,则转换运行顺利,并且我在 XSL 中的所有 XPath 都运行良好。
<book>
<title>Something</title>
</book>
我的问题是:是否有某种方法可以忽略确定架构位置等的那几行代码????
先感谢您!
Java类:
public static void generirajPDF() {
try {
// Setup directories
File baseDir = new File(".");
File outDir = new File(baseDir, "pdf");
outDir.mkdirs();
// Setup input and output files
File xmlfile = new File(baseDir, "WebContent/AvtoSolaZ2.xml");
File xsltfile = new File(baseDir, "WebContent/AvtoSolaZaposleniXSL.xsl");
File pdffile = new File(outDir, "Test.pdf");
// configure fopFactory as desired
FopFactory fopFactory = FopFactory.newInstance();
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
// configure foUserAgent as desired
// Setup output
OutputStream out = new java.io.FileOutputStream(pdffile);
out = new java.io.BufferedOutputStream(out);
try {
// Construct fop with desired output format
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
// Setup XSLT
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory
.newTransformer(new StreamSource(xsltfile));
// Set the value of a <param> in the stylesheet
transformer.setParameter("versionParam", "2.0");
// Setup input for XSLT transformation
Source src = new StreamSource(xmlfile);
// Resulting SAX events (the generated FO) must be piped through
// to FOP
Result res = new SAXResult(fop.getDefaultHandler());
// Start XSLT transformation and FOP processing
transformer.transform(src, res);
} finally {
out.close();
}
if (pdffile.toString().endsWith(".pdf"))
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + pdffile);
else {
Desktop desktop = Desktop.getDesktop();
desktop.open(pdffile);
}
System.out.println("Konec");
} catch (Exception e) {
e.printStackTrace(System.err);
System.exit(-1);
}
}