简体   繁体   中英

Error of XSLT with Eclipse Kepler

I wrote two files

The first file is NewFile.xml(I wrote <?xml-stylesheet type="text/xsl" href="NewStylesheet.xsl"?> in this file) and The second file is NewStylesheet.xsl(Although I do not think there are errors in xsl file, I posted it anyways):

<?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>

However, when I run "XSL Transformation" The error occurs:

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)

Why it says that Caused by: java.io.FileNotFoundException: /Applications/eclipse/Eclipse.app/Contents/MacOS/NewStylesheet.xsl (No such file or directory) ? Any help here?

The current directory when the transformation runs in the Eclipse install directory not the directory containing the files so The href="NewStylesheet.xsl" is looking in the wrong place.

According to this Tutorial you do not put a <?xml-stylesheet in the XML file. Just right click on the XSL file and select XSL Transformation .

This documentation says that you can select a XSL file and a XML file. It also says you can use the Run Configuration to configure what XSL to use for a XML file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM