Project

Profile

Help

Invoke Transformation by specifying template

Added by Anonymous over 19 years ago

Legacy ID: #3172380 Legacy Poster: Theo Gülcher (gulcher)

I am trying the Up-conversion using XSLT 2.0 GEDCOM example. I want to make the Stage One conversion from a GEDCOM file to RAW XML from Java: My code is: private static FileOutputStream transform() { FileOutputStream out = null; try { TransformerFactory factory = TransformerFactory.newInstance(); StreamSource xsl = new StreamSource("gedcom2rawxml.xsl"); Templates templates = factory.newTemplates(xsl); Transformer transformer = templates.newTransformer(); out = new FileOutputStream("family.xml"); File in = new File("family.ged"); transformer.setParameter("input", readFile(in)); StreamResult result = new StreamResult(out); StreamSource source = new StreamSource(sourcePath); transformer.transform(source, result); net.sf.saxon.Transform t = new net.sf.saxon.Transform(); t. } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return out; } When I run this I get: Error on line 1 of file:/g:/family/myfamily.ged: SXXP0003: Error reported by XML parser: Document root element is missing. net.sf.saxon.trans.DynamicError: org.xml.sax.SAXParseException: Document root element is missing. Can someone help me by getting this textfile to transform? Thanks in advance! Theo.


Replies (1)

RE: Invoke Transformation by specifying templ - Added by Anonymous over 19 years ago

Legacy ID: #3172427 Legacy Poster: Michael Kay (mhkay)

This stylesheet uses a named template as its entry point, and has no source document. From the command line you can run this by specifying "-it main" and not specifying a source file. From JAXP (or JAXP as extended by Saxon to handle XSLT 2.0) you specify the initial template using ((Controller)transformer).setInitialTemplate(initialTemplate) and you can supply "null" as the source parameter to the transform() method. If I remember rightly the stylesheet expects the input parameter to be a relative URI, I'm not sure what readFile() does but it's possible you're supplying the contents of the file rather than its name. Michael Kay

    (1-1/1)

    Please register to reply