Module
Contents
Index 🔎︎

# Creating XML Filters

## Creating an XML Filter for LibreOffice

When you create an XML filter for LibreOffice, you need to design an \<emph\>XSLT stylesheet\</emph\> that can convert to and from the OpenDocument XML file format.

For more information about the OpenDocument XML format, go to http://xml.openoffice.org/.

If you want, you can include a \<emph\>template\</emph\> with your filter to apply LibreOffice styles to an XML document that you import.

## To create an XML filter

1. Create an XSLT transformation \<emph\>stylesheet\</emph\> that maps the elements of the external XML format to the elements of the OpenDocument XML file format and back again.

2. Create a template that assigns LibreOffice styles to elements in the external XML format when you import a file in this format into LibreOffice.

3. In LibreOffice Writer, create a text document, and choose \<item type=\"menuitem\"\>Tools - XML Filter Settings\</item\>.

4. Click \<emph\>New\</emph\>.

5. In the \<emph\>XML Filter\</emph\> dialog, click the \<emph\>General\</emph\> tab, and define the properties of the filter.

- In the \<emph\>Filter Name\</emph\> box, enter a name for the XML filter.

  This name is displayed in the \<emph\>XML Filter Settings\</emph\> dialog.

- In the \<emph\>Application\</emph\> box, select the LibreOffice application that the filter is for.

- In the \<emph\>Name of File Type\</emph\> box, enter the file type that the filter is for.

  This name is displayed in the list of file types in the \<emph\>Open\</emph\>, \<emph\>Export\</emph\>, and \<emph\>Save As\</emph\> dialogs.

- In the \<emph\>File extension\</emph\> box, enter the extension for the exported file.

  To differentiate the file from other XML files, enter an extension other than *.xml.

6. On the \<emph\>Transformation\</emph\> tab page, define the transformation properties for the filter.

- (Optional) In the \<emph\>DocType\</emph\> box, enter the document type identifier for the external file format.

  This identifier is used to detect the file type on import.

- In the \<emph\>XSLT for export\</emph\> box, enter the path and file name of the XSLT stylesheet that defines the transformation from OpenDocument format to the external format.

- In the \<emph\>XSLT for import\</emph\> box, enter the path and file name to the XSLT stylesheet that defines the transformation from the external format to OpenDocument format.

- (Optional) In the \<emph\>Template for import\</emph\> box, enter the path and name of the template that defines the LibreOffice styles that are used in the imported file.

  The files that are specified on the \<emph\>Transformation\</emph\> tab page are copied to the local LibreOffice users directory.

7. Click \<emph\>OK\</emph\>.

## To test an XML filter

You can perform basic tests on a custom XML filter in LibreOffice.

The document is not altered by these tests.

1. Create or open a text document.

2. Choose \<item type=\"menuitem\"\>Tools - XML Filter Settings\</item\>.

3. In the list of filters, select the filter that you want to test, and click \<emph\>Text XSLTs\</emph\>.

4. To test an \<emph\>Export\</emph\> Filter, do one of the following in the \<emph\>Export\</emph\> area of the dialog:

- Click \<emph\>Browse\</emph\>, select the LibreOffice document that you want to test, and click \<emph\>Open\</emph\>.

- To test the current document, click \<emph\>Current Document\</emph\>.

5. To test an \<emph\>Import\</emph\> Filter, click \<emph\>Browse\</emph\> in the \<emph\>Import\</emph\> area of the dialog, select a document, and click \<emph\>Open\</emph\>.

Related Topics

About XML Filters

Distributing XML filters