| View previous topic :: View next topic |
| Author |
Message |
bracho General User

Joined: 12 Dec 2008 Posts: 19
|
Posted: Tue Apr 24, 2012 9:08 am Post subject: [Writer] XSL Stylesheet to transform "content.xml" |
|
|
Hi everyone.
I'm trying to convert a TextRange from a Writer document into a HTML string (in order to insert it into a "customized" HTML export).
This TextRange is by the way also exported as an autotext, which "content.xml" could also be a source for my export.
I didn't succeed in doing this. The only way I found was to copy this TextRange, then paste it into a blank document, export this document and extract the HTML code between <body> and </body> (which method is not acceptable).
Does anyone have an idea on how to directly convert such a text range, or to convert the content.xml extracted from the .bau file ?
Many thanks in advance !
Last edited by bracho on Thu Apr 26, 2012 2:44 am; edited 1 time in total |
|
| Back to top |
|
 |
bracho General User

Joined: 12 Dec 2008 Posts: 19
|
Posted: Thu Apr 26, 2012 2:43 am Post subject: |
|
|
Hi everyone.
I made some progress, and managed to do this, which takes as parameter the path to an autotext group and tne name of an entry in this group, and returns as a string the HTML transformation of this entry's "content.xml" :
| Code: | public static String transfromAutotextContentXML2HTML(String sCheminAutotextes,String sRaccourci){
ZipFile zipFile;
String sFiltreXSL = Constantes.REP_CONF + "data\\odt2html2.xsl";
try {
zipFile = new ZipFile(new File(sCheminAutotextes));
ZipEntry zipFormule = zipFile.getEntry(sRaccourci.toUpperCase()+"/"+"content.xml");
InputStream inputStreamNew = zipFile.getInputStream(zipFormule);
SAXTransformerFactory transformerFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
XMLFilter filtreXML = transformerFactory.newXMLFilter(new StreamSource(sFiltreXSL));
SAXSource source = new SAXSource(filtreXML, new InputSource(inputStreamNew));
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
StreamResult resultat = new StreamResult(outStream);
Transformer transformer = transformerFactory.newTransformer();
transformer.transform(source, resultat);
String sChaineHTML = outStream.toString("UTF-8");
return sChaineHTML.substring(sChaineHTML.indexOf("<body>"));
} catch (ZipException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
|
I'm almost there, but I can't find on the web a complete xsl stylesheet that converts odt to html.
Did anyone work on that ?
Many thanks in advance. |
|
| Back to top |
|
 |
DVezina OOo Advocate

Joined: 29 Sep 2006 Posts: 248 Location: Orlando
|
Posted: Mon May 07, 2012 7:55 am Post subject: |
|
|
I haven't found an XSL stylesheet for converting content.xml to HTML. If you find one, please post a link.
My code opens file in OpenOffice (Hidden property set to false) and writes back out to HTML. Then I call an XSLT to add in my JavaScript and insert images for the website.
If you seach for:
HTML AND convert
in this forum you will find a lot of different options. |
|
| Back to top |
|
 |
|