Search code examples
xproc

Output port with default fallback value?


(This is the counterpart of Source port with default fallback value?)

I have an XProc pipeline where I would like the output to work like this:

  • if a URL is provided on the command line using -oresult=foo.xml, then the result of the pipeline is written into that document;
  • if no URL is provided, then the result should be written into default.xml.

Is it possible to obtain this behaviour in XProc?

The difference with the case of the default value for the input port is that the content of the <p:output> element are used as the default source of the output port, not the default output.


Solution

  • I don't think this is possible with standard XProc. While you can provide default connections on input declarations, the situation is different for output ports. In short, there is no such thing as a default connection (in the sense that you can override it from the outside) for output declarations. What may be confusing is that the specification of p:output does allow output connections in declarations of compound steps (and only compound steps, not atomic steps) - but these do not act as default connections. Instead, they say where the data that appears on the output port comes from (typically an output port of a contained step, but it can also be a static or an external document). You also cannot override these output connections because then you would be potentially changing the dependency graph of the pipeline.

    You can think about a "connection" in XProc (represented by p:document, p:pipe, p:inline, p:data, p:empty) as a source to read data from, and not a location to write data to. Similarly a step is a black box that reads data from somewhere and results pour out of it. In this model, the step does not really care about what happens to its results or where they end up stored - that is the responsibility of other steps connected to that step or, in the case of the top-level pipeline, of the XProc processor.

    If you really need default output connections, a possible workaround might be using steps such as p:store and adding optional options (whose values you can override) to the top-level pipeline, but I am not sure that's what you are after.