...
Extraction of XML document packed in a field of other XML
desc
Code Block |
---|
source |
Substitution of current date in the test message
desc
Code Block |
---|
source |
XSLT for other encodings than UTF-8
desc
...
If one the fields of the XML, for example <FieldWithData> contains in itself other XML as escaped text:
Code Block | ||
---|---|---|
| ||
<Data>
<FieldWithData><f1 a1="a1_val"><f2>val2</f2><f3>val3</f3></f1></FieldWithData>
</Data> |
you can extract it using below XSLT before IFTT XML comparison:
Code Block | ||
---|---|---|
| ||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="FieldWithData/text()">
<xsl:value-of disable-output-escaping="yes" select="."/>
</xsl:template>
</xsl:stylesheet> |
Using this technique will allow you to compare the content of <FieldWithData> as XML, not as one long value of a single field.
In case this XML is in addition stored in the CDATA, you can try to reuse the following XSLT mapping:
Code Block | ||
---|---|---|
| ||
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:element name="FieldWithData">
<xsl:value-of select="//FieldWithData" disable-output-escaping="yes"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet> |
XSLT for other encodings than UTF-8
Suppose your XML is encoded not in UTF-8, and you are missing some characters during output comparison in IFTT. In that case, you can use the simple XSLT provided below, which will remove encoding and allow the XSLT engine to convert the message to UTF-8. This is implicit XSLT engine conversion.
Code Block | ||
---|---|---|
| ||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet> |
Different order of XML nodes in a new solution
Different order of XML nodes in a new solution
Sorting XML
If your reference and current XML structures are in a different order you can run below XSLT to sort them before comparision:
Code Block |
---|
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="<PARENT>">
<xsl:copy>
<xsl:apply-templates select="@* | node()[not(self::<CHILD>)]"/>
<xsl:apply-templates select="<CHILD>">
<xsl:sort select="<SORT_BY>" order="ascending"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet> |
<PARENT> - node name of the parent node of the node to be sorted
<CHILD> - node to be sorted
<SORT_BY> - by which field in <CHILD> it should be sorted