Node Functions
Overview
Namespace urn:NodeFunctions
Available Since Zynk Workflow 2.1.4
This article will outline how to implement the node functions that we have made available in Zynk.
You can make use of the node 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:NodeFunctions="urn:NodeFunctions"
exclude-result-prefixes="NodeFunctions">
<!-- transformation -->
</xsl:stylesheet>
Functions
- Select(XPathNodeIterator context, string xpath)
- XPathNodeIterator context - The node to run the xpath expression against. This would typically be the current node, '.'.
- string xpath - The XPath query to return the desired node value.
Example
Input
<?xml version="1.0" encoding="utf-8"?>
<Company>
<Products>
<Product>
<Sku>ABC</Sku>
<Supplier>Bob</Supplier>
<Priority>2</Priority>
</Product>
<Product>
<Sku>ABC</Sku>
<Supplier>Jon</Supplier>
<Priority>3</Priority>
</Product>
<Product>
<Sku>ABC</Sku>
<Supplier>Sam</Supplier>
<Priority>1</Priority>
</Product>
<Product>
<Sku>ZXY</Sku>
<Supplier>Sam</Supplier>
<Priority>1</Priority>
</Product>
<Product>
<Sku>123</Sku>
<Supplier>Bob</Supplier>
<Priority>2</Priority>
</Product>
<Product>
<Sku>123</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:NodeFunctions="urn:NodeFunctions"
exclude-result-prefixes="NodeFunctions">
<xsl:output indent="yes"/>
<xsl:template match="/Company">
<SampleOutput>
<xsl:variable name="DynamicXPath">Products/Product[Priority=1]</xsl:variable>
<xsl:for-each select="NodeFunctions:Select(., $DynamicXPath)">
<Priority><xsl:value-of select="concat('[', Priority, '] ', Sku)" /></Priority>
</xsl:for-each>
</SampleOutput>
</xsl:template>
</xsl:stylesheet>
Output
<?xml version="1.0" encoding="utf-8"?>
<SampleOutput>
<Priority>[1] ABC</Priority>
<Priority>[1] ZXY</Priority>
<Priority>[1] 123</Priority>
</SampleOutput>