OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

[Writer] XSL Stylesheet to transform "content.xml"

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
bracho
General User
General User


Joined: 12 Dec 2008
Posts: 19

PostPosted: Tue Apr 24, 2012 9:08 am    Post subject: [Writer] XSL Stylesheet to transform "content.xml" Reply with quote

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
View user's profile Send private message
bracho
General User
General User


Joined: 12 Dec 2008
Posts: 19

PostPosted: Thu Apr 26, 2012 2:43 am    Post subject: Reply with quote

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
View user's profile Send private message
DVezina
OOo Advocate
OOo Advocate


Joined: 29 Sep 2006
Posts: 248
Location: Orlando

PostPosted: Mon May 07, 2012 7:55 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group