This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new Linux.com!

Linux.com

Feature: Office Software

Export Writer documents into any wiki format

By Dmitri Popov on September 27, 2007 (4:00:00 PM)

Share    Print    Comments   

One of the most welcome additions to OpenOffice.org 2.3 is a new export filter that allows you to save Writer documents as MediaWiki-formatted pages. That's all fine and dandy if you are using MediaWiki, but what about other wiki systems? The answer to this question comes in the form of the OpenOffice2UniWakka export filter. While it's designed to work with the UniWakka wiki, with a bit of hacking you can adapt it to other wiki systems as well, even if you are not familiar with XML and XSLT.

The OpenOffice2UniWakka filter itself consists of the OD2UniWakka.xslt file (or OOo2UniWakka.xslt, if you are still using OpenOffice.org 1.x.x). You can think of this file as a simple conversion program written in XSLT (Extensible Stylesheet Language Transformations), "an XML-based language used for the transformation of XML documents into other XML or human-readable documents." Since the content of an .odt document is stored as an XML file, XSLT is a perfect tool for transforming Writer documents into wiki-formatted text files.

To start hacking the OpenOffice2UniWakka filter, download its latest version from UniWakka's main page and unpack it, then open the OD2UniWakka.xslt file in a text editor. Let's start seeing how we can modify the output with something simple like specifying transformation rules for basic formatting, including bold, italic, and underlined. The filter defines three variables that describe each style: font-style, font-weight, and font-underline:

<xsl:variable name="font-style" select="//office:automatic-styles/style:style[@style:name=$style]/style:text-properties/@fo:font-style"/>
<xsl:variable name="font-weight" select="//office:automatic-styles/style:style[@style:name=$style]/style:text-properties/@fo:font-weight"/>
<xsl:variable name="font-underline" select="//office:automatic-styles/style:style[@style:name=$style]/style:text-properties/@style:text-underline-style"/>

It then finds all text fragments containing the specified formatting and wraps them in wiki markup:

<xsl:when test="$font-weight='bold' and $font-style='italic' and $font-underline='none'">**//</xsl:when>

This means that all you have to do is to locate all the statements that start with <xsl:when test= followed by the "style" condition, and replace the existing markup with the one you want.

The XSLT file also contains a separate section called "my styles" (it starts with the <--! my styles --> comment) where you can specify custom transformation rules. If you take a closer look at the default transformation rules, you'll quickly notice that each rule has the following structure:

<xsl:template match="//text:span[@text:style-name='emph']">
   <xsl:text disable-output-escaping="yes">**</xsl:text>
   <xsl:apply-templates/>
   <xsl:text disable-output-escaping="yes">**</xsl:text>
</xsl:template>

You don't need a degree in rocket science to figure out how the rule works: it simply finds text with a specific style and wraps it in the appropriate wiki markup, so the sentence "This is <b>bold</b>" is converted into "This is **bold**." Knowing that, you can quickly add your own rules. If you are using, for example, DokuWiki, you can create a Writer template containing custom styles like dw-bold, dw-italic, dw-underlined, and so on. You can then specify transformation rules for each style in the "my styles" section of the OD2UniWakka.xslt file:

<xsl:template match="//text:span[@text:style-name='dw-italic']">
   <xsl:text disable-output-escaping="yes">''</xsl:text>
   <xsl:apply-templates/>
   <xsl:text disable-output-escaping="yes">''</xsl:text>
</xsl:template>
<xsl:template match="//text:span[@text:style-name='dw-bold']">
   <xsl:text disable-output-escaping="yes">**</xsl:text>
   <xsl:apply-templates/>
   <xsl:text disable-output-escaping="yes">**</xsl:text>
</xsl:template>

To make use of the defined custom transformation rules, you need to create a Writer template containing the specified styles (i.e. dw-italic, dw-bold, dw-underlined, etc.) and use them to format text.

Once you've figured out the basics, you can tweak the rest of the OD2UniWakka.xslt file. The final step of the process is to add the modified OD2UniWakka filter to OpenOffice.org. To do this, choose Tools -> XML Filter Settings and press the New button. Enter the filter's name in the Filter name field (e.g. "OD2Wiki") and select OpenOffice.org Writer from the Application drop-down list. In the Name of file type field, enter the name of the filter as it will appear in the list of available formats (e.g. "wiki") and enter "txt" in the File extension field. Switch to the Transformation tab, and enter the path to the OD2UniWakka.xslt file in the XSLT for Export field. Press OK, then Close, and the filter is ready to go.

If you want to add the filter to multiple OpenOffice.org installations, or you want to share it with other users, you can export it as a .jar package. To do this, choose Tools -> XML Filter Settings, select the filter, and press the Save as Package button. You and other users can then install the package by simply pressing the Open Package button.

Dmitri Popov is a freelance writer whose articles have appeared in Russian, British, US, German, and Danish computer magazines.

Share    Print    Comments   

Comments

on Export Writer documents into any wiki format

Note: Comments are owned by the poster. We are not responsible for their content.

Importing from MediaWiki would be great too!

Posted by: Anonymous [ip: 216.232.230.164] on September 27, 2007 07:27 PM
It'd be great if there was a feature to copy/paste wiki source code straight into Writer and have it retain the formatting!

#

Re: Importing from MediaWiki would be great too!

Posted by: Anonymous [ip: 219.137.66.239] on December 16, 2007 03:34 AM
Yes, if you can do it, let me know.

<a href="http://www.add2directory.com">Directory Submission Service</a>

<a href="http://www.forexcycle.com">Forex Forecast</a>

<a href="http://blog.forexcycle.com">Forex Blog</a>

<a href="http://forexta.blogspot.com">Online Forex Trading</a>

<a href="http://www.add2directories.com">Add 2 Directories</a>

<a href="http://www.forexarticlecollection.com">Forex Articles</a>

#

classroom helper

Posted by: Anonymous [ip: 66.122.165.195] on September 29, 2007 09:52 PM
As new users of open software increase there will be an inevatable repetition of questions and advice. Perhaps comments should be commented on and placed into a faq. A person submiting a question or comment could use there input as a search query sending them to simmilar content. They could do some cursury research to see if there question has already been sutibly addressed.-also- Probably using the xml or any other sutible method creat a school icon: when clicked a menu pops up that is or has an other blank space to write in the class name. Left click on the class name and pop up a functional dialog box were an href is placed linking you to the class web page. The class page has course outline assignments and study tests that can be down loaded and worked on. When they are done they can be sent back to a student mailbox. If the work is highly formated ex. multiple choice test, it could be linked to a grading program and have the grade posted and the grade average calculated. And a notice of reciept sent to the student with the grade. This is likly allready available using chalkboard programs. However, it seems to be a usful association to the basket idea. The course outline mite contain reaserch refrences or even an actual library to use.
This could be extended to bussiness projects or up the organizational ladder to the principle - teacher and principle - school superintendent modle. Were projects are assigned and assesed.

#

Export Writer documents into any wiki format

Posted by: Anonymous [ip: 83.8.198.158] on October 25, 2007 01:53 AM
Thanks for another very interesting article. Keep up the good work. Regards
<a href="http://www.profesjonalna-reklama.pl" target="_blank">Pozycjonowanie</a> <a href="http://www.topblogposts.info" title="Blog">Tom</a>

#

Export Writer documents into any wiki format

Posted by: Anonymous [ip: 89.59.191.72] on November 05, 2007 04:02 PM
Nice Info, thanks! <a href="http://www.yellobook.eu" title=yellowpages">yellowpages</a>

#

Export Writer documents into any wiki format

Posted by: Anonymous [ip: 82.177.36.10] on December 12, 2007 06:13 PM
This article is very interesting and written by some clever guy.:) Thank you!
<a href="http://www.subasta.pl">Aukcje</a> and <a href="http://www.myplanet.pl">Linki</a>

#

Export Writer documents into any wiki format

Posted by: Anonymous [ip: 212.115.231.38] on December 14, 2007 11:52 AM
<a href="http://majorcars.com.ua/">Крутые тачки</a>
<a href="http://mazda-review.info">Mazda</a>
<a href="http://bupycob.net/">Антивирусы</a>

#

Export Writer documents into any wiki format

Posted by: Anonymous [ip: 88.230.192.187] on December 14, 2007 04:36 PM
<a href="http://www.2zler.com/?p=40" title="karikatür">karikatür</a>
<a href="http://www.2zler.com/karikatur/" title="karikatür">karikatür</a>
<a href="http://www.2zler.com" title="2zler, felek, video,komik videolar, komik video, fıkralar, komik fotoğraflar">komedi</a>
<a href="http://www.2zler.com" title="2zler, felek, video,komik videolar, komik video, fıkralar, komik fotoğraflar">karikatür</a>

#

Export Writer documents into any wiki format

Posted by: Anonymous [ip: 82.207.51.139] on December 15, 2007 04:14 AM
strange that here no admin which cleaned post, in principle <A HREF="http://00j.org/">
I ready </a>

#

Export Writer documents into any wiki format

Posted by: Anonymous [ip: 82.207.61.3] on December 17, 2007 05:59 PM
Вопрос очень интересный - на странице много комментариев явного рекламного направления с активными ссылками, - никто нен чистит данную страничку, но и просмотр сайтов которые здесь заопстили особо не радует их владельцев гугль не считает ссылки с данной страницы - но ведь она имеет на сегодня ПР 7 - странно, но смысла здесь постить вроде как нет, итак чисто для експеримента пробую один <A HREF="http://www.stroimsami.org/">сайтик</a>
и смотрим на его беки через месяц и вы не увидите эту страничку в беках, хотя по идее <A HREF="http://www.diz1.org/">7 пр</a> должна выскакивать в беки гораздо быстрее

#

Export Writer documents into any wiki format

Posted by: Anonymous [ip: 212.115.231.38] on December 18, 2007 07:12 PM
,беки отключили несколько дней назад, до этого все прекрасно наживались на 7рке:)

#

Hmmm

Posted by: Anonymous [ip: 72.236.163.214] on January 04, 2008 10:02 PM
I didn't even realize this feature was in the new version of Open Office. It certainly will come in useful, as this is something I am frequently involved in. Great job with the article! <a href="http://www.javasigns.com/decals">custom decals</a>

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya