我正在尝试使用变压器工厂编译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语法但不能理解错误。
答案 0 :(得分:1)
替换
<xsl:template match="@* | node()">
<xsl:copy-of>
<xsl:apply-templates select="@* | node()" />
</xsl:copy-of>
</xsl:template>
与
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>