I am trying to save XML file to CSV with java, but I receive 'Namespace prefix 'lst' is undeclared' error message.
This is XSL file:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match="/listInvoice">
<!-- header -->
<xsl:text>nieco </xsl:text>
<!-- data -->
<xsl:for-each select="lst:invoice/inv:invoiceHeader">
<!-- classroom data -->
<xsl:variable name="inv:invoiceHeader">
<xsl:value-of select="@inv:id" />
<xsl:text>,</xsl:text>
</xsl:variable>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
This is XML file:
<?xml version="1.0" encoding="UTF-8"?>
<listInvoice>
<lst:invoice>
<inv:invoiceHeader>
<inv:id>9136</inv:id>
<inv:invoiceType>issuedInvoice</inv:invoiceType>
<inv:number>
<typ:id>435</typ:id>
<typ:numberRequested>1710203</typ:numberRequested>
</inv:number>
</inv:invoiceHeader>
</lst:invoice>
</listInvoice>
java code:
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.w3c.dom.Document;
class XMLtoCsVConversion2 {
public static void main(String args[]) throws Exception {
File stylesheet = new File("new.xsl");
File xmlSource = new File("test.xml");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(xmlSource);
StreamSource stylesource = new StreamSource(stylesheet);
Transformer transformer = TransformerFactory.newInstance()
.newTransformer(stylesource);
Source source = new DOMSource(document);
Result outputTarget = new StreamResult(new File("xyz.csv"));
transformer.transform(source, outputTarget);
}
}
Could you please help where could be the problem? Could be the reason be xml tag consist of 2 parts splitted by semicolon?
Thanks