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:hash

<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>

The <p:hash> step generates a so-called hash value. With the help of such values, unique strings can be generated. At the input port (“source“) the document must be defined which shall get the hash value. At the output port the result is outputted. Furthermore, special values can be passed on to the “parameters“ input port having an influence on the generation of the hash value. There are four options to choose from, but three of them are obligatory.

The “value“ option requires a string. Based on that string, the later hash value is generated. The options “algorithm“ (crc,md,sha) and “version“ (32,5,1) determine which algorithm shall be used when generating the value. With the help of “match“, the user has to determine at which position in the document the hash value shall be entered (by an appropriate XSLT expression). The indications of “value“, “match“ and “algorithm“ are required.

Example

In the following example a hash value is generated and written into the known target document.

<?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:output port="result"/>
   <p:hash value="TestValue" algorithm="crc" match="/FilmCollection/Film/Title/@id">
      <p:input port="source">
         <p:pipe port="source" step="Pipeline"/>
      </p:input>
      <p:input port="parameters">
         <p:empty/>
      </p:input>
   </p:hash>
</p:declare-step>

On the basis of the “TestValue“ value, a hash value based on the “crc“ algorithm is generated. This value shall be entered into each of the “id“ attributes at the input port starting from the “FilmCollection.xml“ document. This is determined by the appropriate XSLT expression in the “match“ attribute of <p:hash>. As an attribute of <p:hash>, the initial test value and the used algorithm are entered.

The result is as follows (excerpt):

<Title id="1eb147c8">Star Wars: Episode IV - A New Hope</Title>