The <p:compare> step compares two documents regarding their “equality“. If both documents are identical, the Boolean value “true“ is outputted as a return value. Otherwise “false“.
In the example two documents are compared.
<?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" name="Pipeline"> <p:input port="source"> <p:document href="FilmCollection.xml"/> </p:input> <p:input port="alternate"> <p:document href="FilmCollection_2.xml"/> </p:input> <p:output port="result"/> <p:compare name="Compare" fail-if-not-equal="false"> <p:input port="source"> <p:pipe port="source" step="Pipeline"/> </p:input> <p:input port="alternate"> <p:pipe port="alternate" step="Pipeline"/> </p:input> </p:compare> <p:identity> <p:input port="source"> <p:pipe port="result" step="Compare"/> </p:input> </p:identity> </p:declare-step>
In this example the documents “FilmCollection.xml“ and “FilmCollection_2.xml“ are compared. The pipeline receives a name (“Pipeline“) in the root element <p:declare-step> in order to be able to connect the pipeline afterwards with the appropriate ports in the <p:compare> step. The “Compare“ string is assigned as a name to the <p:compare> step and “fail-if-not-equal“ is set to “false“. As a consequence, “true“ or “false“ is outputted as a result. Otherwise a dynamic error would be outputted by the XProc processor.
As mentioned at the beginning, the two input ports within <p:compare> are connected with the outer “input ports“ via <p:pipe>. In order to realise that, the “step“ attribute needs the name of the step to be linked (in this example “Pipeline“). Since <p:compare> is now provided with the appropriate documents, the process can be started. The result is read by <p:identity> and outputted.
In the case of a difference between the documents, the result would be as follows: