This paragraph describes the built-in commands that come standard with xpt.
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 (http://www.python.org/). 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”.
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
<example-code> <?xpt code import libxml2 import xpt def myFunction(nd,arg1): return "myFunction: nd="+nd.name+" arg1='"+arg1+"'" xpt.registerfunction("myFunction")?></example-code> <example-call> <?xpt myFunction "an argument"?> </example-call>
In the example above, the first processing-instruction using the
code statement registers a new xpt function called
myFunction which is associated with the Python
function with the same name. After evaluation it will be removed from
the output. In the second processing-instruction the xpt function is
evaluated. It will be replaced with the result returned by the Python
function, in example Example 1, “example built-in code usage” that is
the string "myFunction: nd=xpt arg1='an argument'
".
In Python a module variable
__xpt_code_xmlNode__
is set to the libXML2 node
containing the current code statement. The variable is removed when
the execution of the module stops.
![]() | Note |
---|---|
All Python functions that are called from xpt have at least one argument, i.e. a xmlNode pointer referencing the XML element from where the actual call originates. In this is the example-call element. |
See also Section 6.1.6, “loadmodule”. xpt.debug
__dumpdoc
{STRING}
Debugging command which displays the current document to the
standard error output, using STRING
as a message.
Note that debugging output must be enabled by using option -x or environment variable.
__dumpvars
{STRING}
Debugging command which shows a list of currently defined
variables to the standard error output, using
STRING
as a message. Note that debugging output
must be enabled by using option -x or
environment variable.
echo
{STRING}
Evaluate STRING
and replace the
processing-instruction by the string representation.
See also Section 6.1.8, “get”.
error
{STRING
}
Evaluate STRING, report it on the standard error channel and stop processing of the input. No output file will be written. The xpt process returns an exit-code of 1 to the parent process.
python
{python-expression
}
Replace the processing-instruction with the result of the
python-expression
.
get
{NAME
}
Replace the processing-instruction with the value of variable
NAME
.
Example 3. example built-in get usage
<?xpt get __hostname__?>
Evaluation of the processing-instruction above gives: pluto
Here See also Section 6.1.4, “echo”.
select
[NAME
] {XPATH
}
Replace the processing-instruction with the result of the
XPATH
expression. If
NAME
is given the result is saved in a
variable and the processing-instruction is removed from the
output.
set
NAME
VALUE
Create or replace variable NAME
with
value VALUE
. The node wil be removed from
the output.
Example 4. example built-in set usage
<?xpt set var1 "**** This is var1 ****"?>
Evaluation of the processing-instruction above gives:
In the example above, var1
will have
value **** This is var1 ****
.
Variable substitution: replace ${NAME}
constructions with the value associated the the variable
NAME
. There are shell-like quoting rules: single and
double quotes have different effect.
This paragraph describes the XPT bindings for the Python environment.
import xpt
None fsfuncxpt.debug( | ) ; |
message
;Issue a message on the debug output channel. See -x.
import xpt
None fsfuncxpt.dumpvars( | ) ; |
message
;Write list of XPT variables on the debug output channel. See -x and Section 6.1.3, “dumpvars”.
import xpt
None fsfuncxpt.error( | ) ; |
message
;Write a message
to the standard error
channel and stop processing of the input. See Section 6.1.5, “error”.
import xpt
None fsfuncxpt.registerfunction( | , | |
) ; |
name
;func
;Registers xpt function name
which is
associated with the Python function func
. If
this second parameter is not specified, it's name is assumed to be
identical to name
prefixed with the name of the
module from which the registerfunction
is
called.
import xpt
None fsfuncxpt.warning( | ) ; |
message
;Write a message
to the standard error
channel. See Section 6.1.13, “warning”.
Xpt comes with extra functionality through a library of functions.