Previous Up Next


p:hash

p:hash — Computes a cryptographic hash and inserts it into a document.

Synopsis

<p:declare-step type="p:hash">
     <p:input port="source" primary="true"/>
     <p:output port="result"/>
     <p:input port="parameters" kind="parameter"/>
     <p:option name="value" required="true"/>                      <!-- string -->
     <p:option name="algorithm" required="true"/>                  <!-- QName -->
     <p:option name="match" required="true"/>                      <!-- XSLTMatchPattern -->
     <p:option name="version"/>                                    <!-- string -->
</p:declare-step>

Description

The p:hash step generates a hash, or digital “fingerprint”, for some value and inserts it into the source document at specified location(s).

The algorithm identifies the kind of hash to generate. Standard values are “crc”, “md”, and “sha”. Implementations may support additional values as well.

If a version is not specified, the default version is algorithm-defined. For “crc” it is 32, for “md” it is 5, for “sha” it is 1.

A hash is constructed from the string specified in the value option using the specified algorithm and version. The resulting hash is usually returned as a string of hexadecimal characters.

Each matching node in the source document is replaced by the computed hash (if more than one node matches, the same hash value is used as the replacement each time). If the matched node is an attribute, then the computed hash is used as the new attribute value, in all other cases, the entire node is replaced.

Errors

Error Description
err:C0036 Occurs if the requested hash algorithm is not one that the processor understands or if the value or parameters are not appropriate for that algorithm.

Examples

The FOAF (“friend of a friend”) project specifies an SHA1 checksum as an alternative for email addresses (so that the addresses can't be harvested by spammers).

  1 <p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
                xmlns:foaf="http://xmlns.com/foaf/0.1/"
                version="1.0">
  5 
      <p:hash algorithm="sha" version="1"
              match="/*/foaf:mbox_sha1sum/node()">
        <p:with-option name="value"
                       select="/*/foaf:mbox/@rdf:resource"/>
 10   </p:hash>
    </p:pipeline>
Input Output
1 <foaf:Person xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
rdf:about="http://norman.walsh.name/knows/who#norman-walsh">
<foaf:name>Norman Walsh</foaf:name>
5 <foaf:nick>norm</foaf:nick>
<foaf:nick>ndw</foaf:nick>
<foaf:nick>nwalsh</foaf:nick>
<foaf:mbox rdf:resource="mailto:ndw@nwalsh.com"/>
<foaf:mbox_sha1sum>@@</foaf:mbox_sha1sum>
10 </foaf:Person>
 
1 <foaf:Person xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
rdf:about="http://norman.walsh.name/knows/who#norman-walsh">
<foaf:name>Norman Walsh</foaf:name>
5 <foaf:nick>norm</foaf:nick>
<foaf:nick>ndw</foaf:nick>
<foaf:nick>nwalsh</foaf:nick>
<foaf:mbox rdf:resource="mailto:ndw@nwalsh.com"/>
<foaf:mbox_sha1sum>9f5c771a25733700b2f96af4f8e6f35c9b0ad327</foaf:mbox_sha1sum>
10 </foaf:Person>