XProc steps
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z
p:for-each
<p:for-each name? = NCName>
((p:iteration-source? &
(p:output |
p:log)*),
subpipeline)
</p:for-each>
The <p:for-each> step is a loop implementation under XProc. In this way, documents which are assigned to this step are successively processed within a loop in a subpipeline. The input has to be provided as a sequence by a previous step (it has to contain several documents). Alternatively, the content can also be provided by <p:iteration-source>.
<p:iteration-source select? = XPathExpression>
(p:empty |
(p:pipe |
p:document |
p:inline |
p:data)+)?
</p:iteration-source>
<p:iteration-source> is only available in <p:for-each>. As an attribute a XPath expression can be passed on which addresses desired contents from the initial document (of the input port). Alternatively, contents can also be loaded and created via <p:document>, <p:inline> and <p:data>. Then, the documents read in are gradually processed in the subpipeline.
Example
In the following example the functionality of the <p:for-each> step is demonstrated.
<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0">
<p:input port="source">
<p:document href="FilmCollection.xml"/>
</p:input>
<p:output port="result" sequence="true"/>
<p:for-each>
<p:iteration-source select="//Year"/>
<p:output port="result"/>
<p:rename match="/Year" new-name="Date"/>
</p:for-each>
</p:declare-step>
The data to be processed are defined by the <p:iteration-source> step. It determines that any “Year“ elements of the source document read in shall be processed. These are sent consecutively to the <p:rename> step which renames the element as “Date“.