p:compare (3.1) 
Compares documents for equality.
<p:declare-step type="p:compare"> <input port="source" primary="true" content-types="any" sequence="false"/> <output port="result" primary="true" content-types="application/xml" sequence="false"/> <input port="alternate" primary="false" content-types="any" sequence="false"/> <output port="differences" primary="false" content-types="any" sequence="true"/> <option name="fail-if-not-equal" as="xs:boolean" required="false" select="false()"/> <option name="method" as="xs:QName?" required="false" select="()"/> <option name="parameters" as="map(xs:QName, item()*)?" required="false" select="()"/> </p:declare-step>
The p:compare step compares the documents appearing on its source and alternate for equality. It returns a simple
XML document containing the boolean result of the comparison.
Ports:
Port | Type | Primary? | Content types | Seq? | Description |
|---|---|---|---|---|---|
|
|
|
|
| Source document to compare. |
|
|
|
|
| An XML document consisting of a single Example: |
|
|
|
|
| Source document to compare. |
|
|
|
|
| If the |
Options:
The p:compare step takes the documents appearing on its source and alternate ports and tests whether these are
equal. Now testing XML documents for equality is not as easy as it sounds: what to do with whitespace, comments, order of attributes, etc. The
default behavior of p:compare is the same as that of the XPath deep-equal() function. Whether other comparison methods are supported is implementation-defined and
therefore dependent on the XProc processor used.
If the fail-if-not-equal option is false (default), the step emits a simple XML document on its
result port, saying true (equal) or false (not equal). If the fail-if-not-equal option
is true and the documents are not equal, error XC0019 is raised.
The following document is compared against what we supply on the alternate port. In this example the comparison checks out
and p:compare returns true.
<texts> <text>Hi there!</text> </texts>
Pipeline document:
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" version="3.0">
<p:input port="source"/>
<p:output port="result"/>
<p:compare>
<p:with-input port="alternate">
<texts>
<text>Hi there!</text>
</texts>
</p:with-input>
</p:compare>
</p:declare-step>Result document:
<c:result xmlns:c="http://www.w3.org/ns/xproc-step">true</c:result>
No document-properties from the documents on the source and/or alternate ports survive. The resulting document has
a content-type document-property set to application/xml and no base-uri
document-property.
Error code | Description |
|---|---|
It is a dynamic error if the documents are not equal according to the specified comparison | |
It is a dynamic error if the comparison | |
It is a dynamic error if the media types of the documents supplied are incompatible with the comparison |
This description of the p:compare step is for XProc version: 3.1. This is a required step (an XProc 3.1 processor must support this).
The formal specification for the p:compare step can be found here.
The p:compare step is part of categories:
The p:compare step is also present in version:
3.0.