Log Functions
Overview
This article explains how to implement log functions in your mapping files when running them in Zynk Workflow.
When you call one of these functions, a message will be written to the log database. If you are running from the Zynk Workflow application, the message will also be shown in the log panel.
- Namespace urn:ZynkLogFunctions
- Available since Zynk Workflow 2023.6.2
XSLT
Declarations
To use log 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:Log="urn:ZynkLogFunctions"
exclude-result-prefixes="Log">
<!-- transformation -->
</xsl:stylesheet>
Functions
Below is a list of available functions within the urn:ZynkLogFunctions
namespace:
- Info
string message
- Debug
string message
- Warning
string message
- Error
string message
Example
Input
<?xml version="1.0" encoding="utf-8"?>
<Company>
<Products>
<Product>
<Sku>CALC0001</Sku>
<Name>Basic Calculator</Name>
<Description />
</Product>
<Product>
<Sku>CALC0002</Sku>
<Name>Pocket Calculator</Name>
<Description>You can take this fantastic, pocket sized calculator anywhere with you!</Description>
</Product>
</Products>
</Company>
XSLT
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:Log="urn:ZynkLogFunctions"
exclude-result-prefixes="msxsl Log">
<xsl:output indent="yes"/>
<xsl:template match="/">
<products>
<xsl:for-each select="Company/Products/Product">
<xsl:choose>
<xsl:when test="string-length(Description) = 0">
<xsl:variable name="SingleQuote">'</xsl:variable>
<xsl:variable name="Message" select="concat('The product with SKU, ', $SingleQuote, Sku, $SingleQuote, ', does not have a description.')"/>
<xsl:variable name="Error" select="Log:Error($Message)"/>
<xsl:comment><xsl:value-of select="$Message"/></xsl:comment>
</xsl:when>
<xsl:otherwise>
<product>
<sku><xsl:value-of select="Sku"/></sku>
<title><xsl:value-of select="Name"/></title>
</product>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</products>
</xsl:template>
</xsl:stylesheet>
Output
<?xml version="1.0" encoding="utf-8"?>
<products>
<!--The product with SKU, 'CALC0001', does not have a description.-->
<product>
<sku>CALC0002</sku>
<title>Pocket Calculator</title>
</product>
</products>