Sto cercando di effettuare una trasformazione da un file xml a un'altro file xml con un file xslt; il problema è che mi genera un errore che non capisco da dove provenga:
Exception in thread "main" java.lang.IllegalStateException: Root element not set
at org.jdom.Document.getContent(Document.java:408)
at org.jdom.output.XMLOutputter.output(XMLOutputter.j ava:369)
at org.jdom.output.XMLOutputter.output(XMLOutputter.j ava:203)
questo è il file xml:
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schem...ebflow-2.0.xsd">
<start-state id="start">
<view-state xmlns="" id="Casa_Editrice">
<transition on="relazione1" to="Other_MultipleTopic" />
</view-state>
<view-state xmlns="" id="Casa_Editrice">
<transition on="Produce" to="Libro" />
</view-state>
<view-state xmlns="" id="Libro">
<transition on="Edito_da" to="Casa_Editrice" />
</view-state>
<view-state xmlns="" id="Other_MultipleTopic">
<transition on="relazione2" to="Casa_Editrice" />
</view-state>
</start-state>
<end-state id="end" />
</flow>
questo è un file xsl che provo a applicare al file xml:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
</xsl:template>
<xsl:template match="start-state">
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>
e questo è il codice Java per effettuare la transormazione:
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(xmlFileName);
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer(ne w StreamSource(xsltFileName));
JDOMSource in = new JDOMSource(doc);
JDOMResult out = new JDOMResult();
// Perform the transformation.
transformer.transform(in, out);
XMLOutputter fmt = new XMLOutputter();
Format format = Format.getPrettyFormat();
format.setIndent(" ");
format.setLineSeparator("\n");
fmt.setFormat(format);
fmt.output(out.getDocument(),System.out);
FileOutputStream outs=new FileOutputStream("C:/Users/utente/Documents/NetBeansProjects/Pars/web2.xml");
fmt.output(out.getDocument(),outs);
outs.flush();
outs.close();
//fmt.output( doc, System.out );
// fmt.output( out.getDocument(), System.out );
}
catch (TransformerException e) {
throw new JDOMException("XSLT Transformation failed", e);
}
qualcuno mi sa dire dove sto sbagliando? grazie

Rispondi quotando