我写了两个文件
第一个文件是NewFile.xml(我写了<?xml-stylesheet type="text/xsl" href="NewStylesheet.xsl"?>
在这个文件中)和第二个文件是NewStylesheet.xsl(虽然我不认为xsl文件中有错误,但我仍然发布了它):
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
但是,当我运行“XSL Transformation”时会发生错误:
15:55:02,242 INFO [main] Main - javax.xml.transform.TransformerFactory=null
15:55:02,243 INFO [main] Main - java.endorsed.dirs=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/endorsed
15:55:02,245 INFO [main] Main - launchFile: /Users/xuxu/Documents/workspace/.metadata/.plugins/org.eclipse.wst.xsl.jaxp.launching/launch/launch.xml
15:55:02,299 ERROR [main] JAXPSAXProcessorInvoker - Could not compile stylesheet
15:55:02,300 ERROR [main] JAXPSAXProcessorInvoker - 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:886)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:669)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformerHandler(TransformerFactoryImpl.java:961)
at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.JAXPSAXProcessorInvoker.addStylesheet(JAXPSAXProcessorInvoker.java:136)
at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.JAXPSAXProcessorInvoker.transform(JAXPSAXProcessorInvoker.java:210)
at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.JAXPSAXProcessorInvoker.transform(JAXPSAXProcessorInvoker.java:186)
at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.Main.main(Main.java:73)
Caused by: java.io.FileNotFoundException: /Applications/eclipse/Eclipse.app/Contents/MacOS/NewStylesheet.xsl (No such file or directory)
at java.io.FileInputStream.open(Native Method)
为什么说Caused by: java.io.FileNotFoundException: /Applications/eclipse/Eclipse.app/Contents/MacOS/NewStylesheet.xsl (No such file or directory)
?这里有什么帮助吗?
答案 0 :(得分:1)
转换在Eclipse安装目录中运行时的当前目录而不是包含文件的目录,因此href="NewStylesheet.xsl"
查找的位置错误。
根据this Tutorial,您不将<?xml-stylesheet
放入XML文件中。只需右键单击XSL文件,然后选择XSL Transformation
。
This documentation表示您可以选择XSL文件和 XML文件。它还说你可以使用Run Configuration
来配置用于XML文件的XSL。