File Functions
Overview
Namespace urn:FileFunctions
Available since Zynk Workflow 2.1.4
This article will outline how to implement the file functions that we have made available in Zynk.
You can make use of the file 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
- FileExists(string file)
- ValidXml(string file)
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>
</Products>
</Company>
XSLT
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:FileFunctions="urn:FileFunctions"
exclude-result-prefixes="FileFunctions">
<xsl:output indent="yes"/>
<xsl:param name="InventoryFile">C:\Users\joe.harrison\Downloads\inventory.xml</xsl:param>
<xsl:template match="/">
<StockInfo>
<xsl:choose>
<xsl:when test="FileFunctions:ValidXml($InventoryFile)">
<xsl:for-each select="Company/Products/Product">
<xsl:variable name="SKU" select="Sku"/>
<xsl:variable name="Inventory" select="document($InventoryFile)/InventoryInfo/Inventory[Sku=$SKU]"/>
<Stock>
<xsl:copy-of select="Sku"/>
<Qty><xsl:value-of select="$Inventory/QtyInStock - $Inventory/QtyAllocated"/></Qty>
</Stock>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="SingleQuote">'</xsl:variable>
<xsl:comment><xsl:value-of select="concat('The file, ', $SingleQuote, $InventoryFile, $SingleQuote, ', is not valid XML.')"/></xsl:comment>
</xsl:otherwise>
</xsl:choose>
</StockInfo>
</xsl:template>
</xsl:stylesheet>
Output
<?xml version="1.0" encoding="utf-8"?>
<StockInfo>
<!--The file, 'C:\Users\joe.harrison\Downloads\inventory.xml', is not valid XML.-->
</StockInfo>