p:message (3.1) 
Produces a message.
<p:declare-step type="p:message"> <input port="source" primary="true" content-types="any" sequence="true"/> <output port="result" primary="true" content-types="any" sequence="true"/> <option name="select" as="item()*" required="true"/> <option name="test" as="xs:boolean" required="false" select="true()"/> </p:declare-step>
The p:message step produces a message that is, usually, printed on the console. The effect (when the test option is
true) is the same as using a message/p:message attribute on a step.
Ports:
Port | Type | Primary? | Content types | Seq? | Description |
|---|---|---|---|---|---|
|
|
|
|
| The source document(s). |
|
|
|
|
| The resulting document(s). These will be exactly the same as what appeared on the |
Options:
Steps in general can produce messages by using the message (for steps in the XProc namespace) or p:message (for
steps in other namespaces) attribute. What “produce” here actually means is implementation-defined and therefore depends on the
XProc processor used. However, usually it means “printed on the console” and/or “output through
stdout”: a command-line message appears when the processor executes the step.
The p:message step is an alternative way to produce these messages. When the test option is true (default), the
value of the select option is turned into a string and produced/shown, as a message. If the test option is
false, nothing happens.
The step itself, irrespective of the value of the test option, simply passes what it gets on its source port
unaltered to its result port. In other words, it acts as a p:identity step.
Assume you have a pipeline that does some preliminary things (getting documents, computing variables, etc.) and then starts the real
computation of something. In-between you want a message that says the computation has started, but only when enabled by an option. Here is an
example of how to do this using the p:message step:
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="3.0">
<p:input port="source"/>
<p:output port="result"/>
<p:option name="debug-messages-on" as="xs:boolean" select="true()"/>
<!-- Some preliminary stuff… -->
<p:message test="{$debug-messages-on}" select="Starting computation at {current-dateTime()}"/>
<!-- Steps that implement the computation… -->
</p:declare-step>
It is certainly possible to implement this without the p:message step, using a p:identity step with a
message attribute:
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="3.0">
<p:input port="source"/>
<p:output port="result"/>
<p:option static="true" name="debug-messages-on" as="xs:boolean" select="true()"/>
<!-- Some preliminary stuff… -->
<p:identity use-when="$debug-messages-on" message="Starting computation at {current-dateTime()}"/>
<!-- Steps that implement the computation… -->
</p:declare-step>Please notice that in the first example the on/off switch for the message, here the debug-messages-on option, is
dynamic. It can be computed/set during run-time, if necessary.
However, in the second example, this on/off switch is referenced in a use-when attribute. All use-when attributes
are evaluated during compile-time, and therefore the debug-messages-on option must be static (hence its
static="true" attribute). The only time you can change/set this option, and turn messages on/off, is when invoking the
pipeline.
p:message preserves all document-properties of the document(s) appearing on its source port.