This section contains examples of these simple XSL transformations:
1. Change the value of named nodes with a specific value
2. Insert an extra node in the XML file, if a node with a specific value is found.
In this example we want to change the value of named nodes, that has a specific value. For this example we consider an XML file with this layout:
<IBSFORM>
<DOCUMENT>
<Header>
<General>
<IBSJOBTYPE>E</IBSJOBTYPE>
</General>
</Header>
</DOCUMENT>
</IBSFORM>
We want to change the value if the IBSJOBTYPE node into J, if the value found is E like it is in the example above.
This can be done with an XSL transformation with this specification:
<xsl:stylesheet version="1.0">
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/IBSFORM/DOCUMENT/Header/General/IBSJOBTYPE[text()='E']">
<xsl:value-of select="J"/>
</xsl:template>
</xsl:stylesheet>
In the XSL we search for /IBSFORM/DOCUMENT/Header/General/IBSJOBTYPE nodes, which has the value, E and for those we insert the value 'J' as described.
The implementation in the workflow is similar to the example below: Insert an extra node in the XML file, if a node with a specific value is found
This section includes a simple example of how an xslt can be used for changing an input XML file in the workflow. The object is to search for a node, that contains a specific value, and if that is found, then a extra node should be inserted.
Consider this input XML file:
In the bottom of the file you can see the node, DocumentNO. The task here is to search all the Document nodes to find out, if any of them contains the text '1004'. If that is the case, then a new node should be inserted in the XML file (inside the current Document node).
The additional node is called Found and the contents should be '1004 is found' like so:
The contents of an XSLT that does the trick is shown below:
Here is a workflow, that use the stylesheet to convert the input XML file, use the converted XML as input for a merge with a template and save this and the transformed XML into the file system: