Hash Functions
Overview
Namespace urn:HashFunctions
Available since Zynk Workflow 2.11.0
This article will outline how to implement the hash functions that we have made available in Zynk.
You can make use of the hash functions by including the following declaration in your XSLT document:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:FileFunctions="urn:FileFunctions"
exclude-result-prefixes="FileFunctions">
<!-- transformation -->
</xsl:stylesheet>
Functions
- PopulateHashes(string hashTable, XPathNodeIterator xpath, string keyXPath)
- EmptyHashes(string hashTable)
- IsNew(string hashTable, XPathNodeIterator xpath, string keyXPath)
- HasChanged(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>