XSLT:在氧气工具中出现“在样式表编译期间报告了错误”

时间:2019-07-01 07:38:00

标签: xslt oxygenxml

首先,我的问题不能重复到: How to fix 'Errors were reported during stylesheet compilation' in XSLT?


问题:

我使用氧气编辑器工具运行代码。使用Saxon-HE 9.8.0.12调试器引擎。

这是我的XSLT代码:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
                <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes" />
                <xsl:include href="Global Variables.xsl" />
                <xsl:include href="common/basicDataTypes/basicText.xsl" />
                <xsl:include href="common/basicDataTypes/case.xsl" />
                <xsl:include href="common/basicDataTypes/figure.xsl" />
                <xsl:include href="common/basicDataTypes/links.xsl" />
                <xsl:include href="common/basicDataTypes/list.xsl" />
                <xsl:include href="common/basicDataTypes/text.xsl" />
                <xsl:include href="common/basicDataTypes/wcn.xsl" />
                <xsl:include href="common/dispatch/commonDispatch.xsl" />
                <xsl:include href="common/limit/limit.xsl" />
                <xsl:include href="common/procedure/action.xsl" />
                <xsl:include href="common/procedure/condition.xsl" />
                <xsl:include href="common/procedure/context.xsl" />
                <xsl:include href="common/procedure/failureConsequence.xsl" />
                <xsl:include href="common/procedure/nonNormalProcContent.xsl" />
                <xsl:include href="DataManagement/DmStatus.xsl" />
                <xsl:include href="DataManagement/Pm.xsl" />
                <xsl:include href="DataManagement/PmStatus.xsl" />
                <xsl:include href="Dispatch/DispatchItem.xsl" />
                <xsl:include href="Dispatch/SystemFault.xsl" />
                <xsl:include href="System/SystemDescription.xsl" />

                <xsl:template match="/">
                                <html>
                                                <head>
                                                                <link rel="stylesheet" type="text/css" href="main.css" />
                                                                <link rel="stylesheet" type="text/css" href="special elements.css" />
                                                                <link rel="stylesheet" type="text/css" href="common/basicDataTypes/basicText.css" />
                                                                <link rel="stylesheet" type="text/css" href="common/basicDataTypes/list.css" />
                                                                <link rel="stylesheet" type="text/css" href="common/basicDataTypes/wcn.css" />
                                                                <link rel="stylesheet" type="text/css" href="common/dispatch/commonDispatch.css" />
                                                                <link rel="stylesheet" type="text/css" href="common/limit/limit.css" />
                                                                <link rel="stylesheet" type="text/css" href="common/procedure/context.css" />
                                                                <link rel="stylesheet" type="text/css" href="common/procedure/failureConsequence.css" />
                                                </head>
                                                <body>
                                                                <xsl:comment>
                                                                                This is a comment!
                                                                </xsl:comment>
                                                                <xsl:apply-templates />
                                                                <hr />
                                                </body>
                                </html>
                </xsl:template>
</xsl:stylesheet>

运行代码时出现错误:“在样式表编译期间报告了错误”

问题出在哪里?

1 个答案:

答案 0 :(得分:1)

package stackoverflow; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.StringReader; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import javax.xml.xpath.XPathExpressionException; import org.xml.sax.InputSource; public class XMLTester { public static void main(String[] args) throws SAXException, IOException, ParserConfigurationException, XPathExpressionException { String xmlStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<User xmlns=\"http://abc.e.wat.com/xml\" SOURCE_NAME=\"PublicAssetFeed\">" + " <Employee>" + " <FIELD NAME=\"Name\" TYPE=\"char\">Rahul</FIELD>" + " <FIELD NAME=\"Branch\" TYPE=\"char\" />" + " <FIELD NAME=\"Unique ID\" TYPE=\"char\">12345</FIELD>" + " </Employee>" + "</User>"; Document doc = readStringAsDocument(xmlStr); try { printDocument(doc, System.out); } catch (TransformerException e) { // TODO Auto-generated catch block e.printStackTrace(); } Node willBeDeleted = null; NodeList fieldNodes = doc.getElementsByTagName("FIELD"); if (fieldNodes.getLength() > 0) { for (int i = 0; i < fieldNodes.getLength(); i++) { Node node = fieldNodes.item(i); NamedNodeMap attributes = node.getAttributes(); for (int j = 0; j < attributes.getLength(); j++) { Node att = attributes.item(j); if (att.getNodeName().equals("NAME") && att.getNodeValue().equals("Branch")) { willBeDeleted = node; } } } } willBeDeleted.getParentNode().removeChild(willBeDeleted); try { printDocument(doc, System.out); } catch (TransformerException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private static Document readStringAsDocument(String xmlString) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = null; db = dbf.newDocumentBuilder(); Document doc = db.parse(new InputSource(new StringReader(xmlString))); return doc; } // https://stackoverflow.com/a/2325407/2384806 public static void printDocument(Document doc, OutputStream out) throws IOException, TransformerException { TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transformer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(out, "UTF-8"))); } } 更改为xsl:output method="html" version="1.0",我认为Saxon不支持HTML 1.0,xsl:output method="html" version="5"html和{{1}的5序列化}。

对于所有包含的样式表模块所导致的任何其他错误,您将需要逐步进行并首先对每个模块进行检查。