Purpose preprocessing tool XPT, a XML general-

XPT, a XML generalpurpose preprocessing tool

Bram Latupeirissa

Version 0.1.1 (CVS xpt.xml 1.42 2014/04/13) 2014-04-16

Table of Contents

1. Introduction .............................................................................................................................. 1 2. Functionality ............................................................................................................................ 2 3. XPT command-line options ......................................................................................................... 2 4. Startup and environment ............................................................................................................. 3

4.1. environment ................................................................................................................... 3 4.2. start-up file .................................................................................................................... 3 5. Command syntax ...................................................................................................................... 3 6. Built-in commands .................................................................................................................... 3 6.1. XML bindings ................................................................................................................ 3 6.2. Variable substitution ........................................................................................................ 6 6.3. Python bindings .............................................................................................................. 6 6.4. XPT library ................................................................................................................... 8 7. XPT development ...................................................................................................................... 8 7.1. Sources and build-system ................................................................................................. 8 7.2. Documentation ............................................................................................................... 9 1. Ideas and things todo ................................................................................................................. 9 2. Pointers ................................................................................................................................... 9 3. Manpages ............................................................................................................................... 10

1. Introduction

Somewhere in 2010 I had a project where DocBook XML documents needed to be enriched with data coming from various, non-XML sources. The idea was to have scripting insert DocBook elements into a DocBook template. There were two options, first write a program to convert non-XML data into DocBook XML elements and second write a more generic program to insert DocBook XML elements into the original source. XPT (xml-xpt) does this. It replaces XML processing instructions with target xpt in an XML input file.

This way a library can be setup with (user-) predefined functions.

This document is also available in Acrobat pdf format at .

1

XPT, a XML general-purpose preprocessing tool

2. Functionality

This paragraph presents a global picture about what functionality xpt delivers and how and where to use it. Some use cases.

A DocBook use-case

DocBook is a XML vocabulary () for writing books and articles. Often a make tool-chain is used, where a DocBook XML source is transformed into a certain format, e.g. HTML or PDF. A place where, with every version of a document, manual action is required: releaseinfo and pubdate.

3. XPT command-line options

The following command-line options are recognised by xpt:

xpt [-h] [-k] [-c cmd] [-F] [-i infile] [-I dir] [-n] [-o outfile] [-s cmd] [-t stylesheet] [-T pi-name] [-f all-func] [-P init-cmd] [-D name=[=[value]]] [-x] [-v] [-V]

-c cmd

enter command mode. Currently the following values are allowed:

ppi

process processing-instructions. this is the default value.

version show version information. same as the -V.

-D name[=value] define variable name optionally with value value.

-f all-func

register a single function for all selected XML elements. Usually needs -P option to get function installed.

-F

use fancy XML output format for better readability.

-h

show some help.

-i infile

read XML from infile. If not specified, standard input is assumed. If infile is explicitly specified as - (dash), the standard input is read.

-I dir

append dir to list search directories of xpt and embedded Python engine.

-k

keep temporary files

-n

do not execute external commands

-o outfile

send output to output.

Note

needs extra explanation out how the output is created. read the code.

-P init-cmd

issue init-cmd command before transforming selected elements. Most often a module is loaded using this option. This option may be used more than once.

2

XPT, a XML general-purpose preprocessing tool

-s cmd

use XPath cmd in while creating output.

-t stylesheet

use XSLT stylesheet in output generation

-T pi-name

change name of processing-instruction target to pi-name. Default is xpt.

-x

Show debug output. This option may be used more than once to increase the verbosity.

-v

Be verbose.

-V

Show version information.

4. Startup and environment

4.1. environment

Environment variables that are taken into account: HOME XPT_DEBUG

TMPDIR

4.2. start-up file

used for locating the start-up file, see Section 4.2, "startup file".

enables debugging output (see option -x). The value of the variable sets the debug verbosity level. This option allows debugging of code activated during the reading of the start-up file, see Section 4.2, "start-up file".

determines the location for placement of temporary files.

When xpt starts it checks for the existance of a start-up file.

5. Command syntax

Syntax of the XPT processing instructions. Output redirection (string, XML node, XML nodeset). Comment

6. Built-in commands

This paragraph describes the built-in commands that come standard with xpt.

6.1. XML bindings

This paragraph describes the built-in commands that can be used with processing-instructions in the input XML stream. User-defined commands can be created from the embedded Python engine (). Most commands can have arguments. There are two types of arguments: positional and named arguments. EXPLAIN. Then there is quoting: unquoted, single-quoted and double-quoted. Optionally glueing those parts together. Note that built-in commands (currently?) have no named arguments, only positional. See the section on variable substitution Section 6.2, "Variable substitution".

3

XPT, a XML general-purpose preprocessing tool

6.1.1. code

code NEWLINE CODE Insert a block of executable code. Note that a NEWLINE must be after the code keyword. From that point the text is passed to the Python interpreter. The node wil be removed from the output.

Example 1. example built-in code usage

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download