16. Converting an XML document to other formats

For the purpose of this tutorial, we'll explain how to convert the "Simple Section" document being edited to a single HTML page.

A XSLT stylesheet will be used for this task. Excerpts from rng_section_config/html.xsl (same file for all variants):

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  <xsl:output method="html"
  <xsl:template match="s:bold">
      <xsl:call-template name="processCommonAttributes"/>

It should be noted that XXE has no high-level construct (e.g. an hypothetical convertDocument configuration element) allowing to integrate an XSLT stylesheet. Instead, XXE relies on its menu, toolBar, binding, macro command, process command, etc, to do that.

For example, our "Section" menu element ends with:

  <separator />
  <item label="_Convert to HTML"
        command="sect.convertToHTML" />

Macro-command sect.convertToHTML allows the user to choose a save file for the HTML page which will be the result of the conversion (by the means of native command selectConvertedFile in XMLmind XML Editor - Commands) and then invokes process command sect.toHTML which will perform the conversion. Excerpts from rng_section_config/common.incl (same file for all variants):

<command name="sect.convertToHTML">
      <command name="selectConvertedFile" 
               parameter="saveFileURLWithExtension=html" />
      <command name="sect.toHTML" parameter='"%_"' />1
      <command name="preview" parameter="[lastConverted]" />2

In the above macro,


The command parameter contains "%_". %_ is a macro-variable in XMLmind XML Editor - Commands and it is quoted using double-quote characters in case it contains whitespace. Variable %_ contains the result returned by the last executed command. In the above case, the last executed command is selectConvertedFile and the result it returns is the URI of the save file selected by the user.


Command preview in XMLmind XML Editor - Commands allows to invoke a third-party helper application (e.g. a Web browser) in order to preview the result of the conversion.