XML Transformation
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0" xpath-default-namespace="http://www.w3.org/2005/xpath-functions">
<xsl:output indent="yes" />
<xsl:strip-space elements="*" />
<xsl:param name="json" />
<xsl:mode on-no-match="deep-skip" />
<xsl:template name="init">
<xsl:apply-templates select="json-to-xml($json)" />
</xsl:template>
<xsl:template match="/array">
<Cargos>
<xsl:apply-templates />
</Cargos>
</xsl:template>
<xsl:template match="/array/map | /map">
<Cargo>
<xsl:apply-templates />
</Cargo>
</xsl:template>
<xsl:template match="*[@key='voyage']">
<IsTc>
<xsl:value-of select="*[@key='isTc']" />
</IsTc>
<VesselCode>
<xsl:value-of select="*[@key='vessel']/*[@key='vesselCodes'][1]/*/*[@key='vesselCode']" />
</VesselCode>
<VesselName>
<xsl:value-of select="*[@key='vessel']/*[@key='vesselName']" />
</VesselName>
</xsl:template>
<xsl:template match="*[@key='commodity']">
<CommodityName>
<xsl:value-of select="*[@key='commodityName']" />
</CommodityName>
</xsl:template>
<xsl:template match="*[@key='cargoPorts']">
<xsl:apply-templates select="*/*" />
</xsl:template>
<xsl:template match="*[@key='portCall']">
<xsl:variable name="reasonForCall" select="*[@key='reasonForCall']/*[@key='reasonForCall']" />
<xsl:variable name="name" select="*[@key='port']/*[@key='portName']" />
<xsl:if test="$reasonForCall = 'L' ">
<LoadPort>
<xsl:value-of select="$name" />
</LoadPort>
<LoadPortArrival>
<xsl:apply-templates select="*/*" />
</LoadPortArrival>
</xsl:if>
<xsl:if test="$reasonForCall = 'D' ">
<DischargePort>
<xsl:value-of select="$name" />
</DischargePort>
<DischargePortArrival>
<xsl:apply-templates select="*/*" />
</DischargePortArrival>
</xsl:if>
</xsl:template>
<xsl:template match="*[@key='eventLogs']/*">
<xsl:variable name="code" select="*[@key='event']/*[@key='eventCode'][text() = 'ARR']" />
<xsl:if test="$code">
<xsl:value-of select="*[@key='eventLogDate']" />
</xsl:if>
</xsl:template>
</xsl:stylesheet>Last updated
Was this helpful?