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"
                xmlns:s="http://www.xmlmind.com/ns/sect"
                exclude-result-prefixes="s"
                version="1.0">
  <xsl:output method="html"
              encoding="ISO-8859-1"
              indent="no"/>
  ...  
  <xsl:template match="s:bold">
    <b>
      <xsl:call-template name="processCommonAttributes"/>
      <xsl:apply-templates/>
    </b>
  </xsl:template>
  ...
</xsl:stylesheet>

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"
        icon="xxe-config:common/mime_types/html.png"
        command="sect.convertToHTML" />
</menu>

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">
  <macro>
    <sequence>
      <command name="selectConvertedFile" 
               parameter="saveFileURLWithExtension=html" />
      <command name="sect.toHTML" parameter='"%_"' />1
      <command name="preview" parameter="[lastConverted]" />2
    </sequence>
  </macro>
</command>

In the above macro,

1

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.

2

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.