marcostutu
New Member
I have a little problem. I have to product a HTML file from a XML file using XSLT. But the HTML filename is generated by XML content.In my case i solved my problem as following:\[code\]public File GenerateHTML(File fileIn) { File xsltFile = new File(xsltfileString); File htmlFile = new File(System.getProperty("user.home") + File.separator + "result.html"); File htmlFileFinal = null; Source xmlSource = new StreamSource(fileIn); Source xsltSource = new StreamSource(xsltFile); Result htmlResult = new StreamResult(htmlFile); TransformerFactory transFact = TransformerFactory.newInstance(); Transformer trans; try { trans = transFact.newTransformer(xsltSource); trans.setParameter("filter_xml", filterXML); trans.setParameter("FileName", fileIn.getName()); trans.transform(xmlSource, htmlResult); String outputFileName = (String)trans.getParameter("OutputFilename"); htmlFileFinal = new File(System.getProperty("user.home") + File.separator + outputFileName + ".html"); htmlFile.renameTo(htmlFileFinal); } catch (TransformerConfigurationException ex) { LOGGER.log(Level.FATAL, ex.getMessage(), ex); } catch (TransformerException ex) { LOGGER.log(Level.FATAL, ex.getMessage(), ex); } return htmlFileFinal;}\[/code\]and in my XSLT i do : \[code\]<!-- general settings --><xslutput method="html" omit-xml-declaration="yes" indent="yes" encoding="UTF-8" /><xsl:variable name="filter" select="document($filter_xml)/Filtre/Bloc5" /><!-- transformation body --><xsl:template match="*"> <xslaram name="OutputFilename" select="concat(cac:ContractDocumentReference/cbc:ID, '_', cbc:ID, '_', translate(cbc:IssueDate, '-', ''))" />[...]\[/code\]This solution works, but i asked myself if it is optimized or if there is a trick in XSLT to generate a dynamic HTML ?