我正在尝试使用变压器工厂编译 xsl,但它不断给出异常:
XSL:`
<xsl:output method="xml" indent="yes" encoding="utf-8"
omit-xml-declaration="no" />
<xsl:template match="@* | node()">
<xsl:copy-of>
<xsl:apply-templates select="@* | node()" />
</xsl:copy-of>
</xsl:template>
<xsl:template match="value">
<xsl:element name="value">
<xsl:text>-1</xsl:text>
</xsl:element>
</xsl:template>
<xsl:template match="time">
<xsl:element name="time">
<xsl:text>00:00:00</xsl:text>
</xsl:element>
</xsl:template>
`
代码 :
String xslPath = "C:\\Users\\Vaibhav_Ajmera\\Desktop\\vaib\\";
String findxsl = "find_replace.xsl";
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new javax.xml.transform.stream.StreamSource (xslPath + findxsl));
我经常遇到异常:`
ERROR: 'Syntax error in ''.'
FATAL ERROR: 'Could not compile stylesheet'
javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates (TransformerFactoryImpl.java:843)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer (TransformerFactoryImpl.java:632)
at com.bt.rtsm.processor.merger.MetricReset.transformXml(MetricReset.java:92)
at com.bt.rtsm.processor.merger.MetricReset.metricReset(MetricReset.java:51)
at com.bt.rtsm.processor.merger.MetricReset.main(MetricReset.java:194)
`
有人可以帮忙吗?我猜想它可以用 xsl 语法来做,但无法理解有什么问题。