Probuje przetworzyc XML o nazwie stocks.xml
<?xml version="1.0" encoding="UTF-8"?>
<portfolio>
<stock>
<symbol>SUNW</symbol>
<name>Sun Microsystems</name>
<price>17.1</price>
</stock>
<stock>
<symbol>AOL</symbol>
<name>America Online</name>
<price>51.05</price>
</stock>
<stock>
<symbol>IBM</symbol>
<name>International Business Machines</name>
<price>116.10</price>
</stock>
<stock>
<symbol>MOT</symbol>
<name>MOTOROLA</name>
<price>15.20</price>
</stock>
</portfolio>
wykorzystujac stocks.xsl:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform" version=
"1.0">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="portfolio">
<table border="2" width="50%">
<xsl:for-each select="stock">
<tr>
<td>
<i><xsl:value-of select=
"symbol"/></i>
</td>
<td>
<xsl:value-of select="name"/>
</td>
<td>
<xsl:value-of select="price"/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
oraz kod java:
package xslt;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import java.io.*;
public class Main {
public static String prefix = "file://C:/Documents and Settings/Bartosz/My Documents/NetBeansProjects/XSLT/src/";
public static void main(String[] args)
throws TransformerException,
TransformerConfigurationException,
FileNotFoundException, IOException {
TransformerFactory tFactory =
TransformerFactory.newInstance();
Transformer transformer =
tFactory.newTransformer(
new StreamSource(
prefix + "stocks.xsl"));
transformer.transform(
new StreamSource(prefix + "stocks.xml"),
new StreamResult(new FileOutputStream(
prefix + "stocks.html")));
System.out.println("** The output is written in " +
prefix + "stocks2.html" + " **");
}
}
do pliku html, jednak dostaje blad:
run:
ERROR: 'C'
FATAL ERROR: 'Could not compile stylesheet'
Exception in thread "main" javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:824)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:613)
at xslt.Main.main(Main.java:17)
Java Result: 1
BUILD SUCCESSFUL (total time: 6 seconds)
co moze byc przyczyna?