Hash Functions
Overview
This article will outline how to implement the hash functions that we have made available in Zynk.
- Namespace urn:HashFunctions
- Available since Zynk Workflow 2.11.0
XSLT
Declarations
To use hash functions, you need to add the namespace declaration to your XSLT file:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:HashFunctions="urn:HashFunctions"
exclude-result-prefixes="HashFunctions">
<!-- transformation -->
</xsl:stylesheet>
Functions
- PopulateHashes Seeds a hash table based on the parameters provided.
string hashTable, XPathNodeIterator xpath, string keyXPath
- EmptyHashes Clears the given hash table.
string hashTable
- IsNew Checks if a record is new to the hash table based on the parameters provided.
string hashTable, XPathNodeIterator xpath, string keyXPath
- HasChanged Checks if a record has changed based on the parameters provided.
string hashTable, XPathNodeIterator xpath, string keyXPath
Example
Input
<?xml version="1.0" encoding="utf-8"?>
<Company>
<Products>
<Product>
<Sku>ABC</Sku>
<Supplier>Bob</Supplier>
<Priority>2</Priority>
</Product>
<Product>
<Sku>ZXY</Sku>
<Supplier>Sam</Supplier>
<Priority>1</Priority>
</Product>
<Product>
<Sku>123</Sku>
<Supplier>Jon</Supplier>
<Priority>3</Priority>
</Product>
</Products>
</Company>
XSLT
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:HashFunctions="urn:HashFunctions"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="HashFunctions msxsl">
<xsl:output indent="yes"/>
<xsl:template match="/">
<xsl:variable name="Source">
<Stocks>
<Stock>
<Code>ABC</Code>
</Stock>
<Stock>
<Code>ZXY</Code>
</Stock>
</Stocks>
</xsl:variable>
<xsl:variable name="Populate" select="HashFunctions:PopulateHashes('Products', msxsl:node-set($Source)/Stocks/Stock, 'Code')"/>
<Data>
<xsl:for-each select="Company/Products/Product">
<Datum>
<IsNew><xsl:value-of select="HashFunctions:IsNew('Products', ., 'Sku')"/></IsNew>
</Datum>
</xsl:for-each>
</Data>
</xsl:template>
</xsl:stylesheet>
Output
<?xml version="1.0" encoding="utf-8"?>
<Data>
<Datum>
<IsNew>false</IsNew>
</Datum>
<Datum>
<IsNew>false</IsNew>
</Datum>
<Datum>
<IsNew>true</IsNew>
</Datum>
</Data>