I have a xml file where I need to combine an element's values together to one element and make sure there are no duplicates. Below is the input xml file.
<AIRPORTSFILE>
<document name="SAMPLE1">
<DEPARTURE_AIRPORT>D1</DEPARTURE_AIRPORT>
<DEPARTURE_DATE>2014-03-15</DEPARTURE_DATE>
<DEPARTURE_TIME>0615</DEPARTURE_TIME>
<ARRIVAL_DATE>2014-03-14</ARRIVAL_DATE>
<ARRIVAL_TIME>0930</ARRIVAL_TIME>
<ARRIVAL_AIRPORT>A1</ARRIVAL_AIRPORT>
<DEPARTURE_AIRPORT>D2</DEPARTURE_AIRPORT>
<DEPARTURE_DATE>2014-03-14</DEPARTURE_DATE>
<DEPARTURE_TIME>0615</DEPARTURE_TIME>
<ARRIVAL_DATE>2014-03-15</ARRIVAL_DATE>
<ARRIVAL_TIME>0930</ARRIVAL_TIME>
<ARRIVAL_AIRPORT>A2</ARRIVAL_AIRPORT>
<DEPARTURE_AIRPORT>D2</DEPARTURE_AIRPORT>
<DEPARTURE_DATE>2014-03-15</DEPARTURE_DATE>
<DEPARTURE_TIME>0615</DEPARTURE_TIME>
<ARRIVAL_DATE>2014-03-15</ARRIVAL_DATE>
<ARRIVAL_TIME>0930</ARRIVAL_TIME>
<ARRIVAL_AIRPORT>A2</ARRIVAL_AIRPORT>
</document>
<document name="SAMPLE2">
<DEPARTURE_AIRPORT>2014-06-05</DEPARTURE_AIRPORT>
<DEPARTURE_DATE>2014-06-05</DEPARTURE_DATE>
<DEPARTURE_TIME>1815</DEPARTURE_TIME>
<ARRIVAL_DATE>2014-06-05</ARRIVAL_DATE>
<ARRIVAL_TIME>2130</ARRIVAL_TIME>
<ARRIVAL_AIRPORT>P1</ARRIVAL_AIRPORT>
<DEPARTURE_AIRPORT>2014-06-06</DEPARTURE_AIRPORT>
<DEPARTURE_DATE>2014-06-06</DEPARTURE_DATE>
<DEPARTURE_TIME>1815</DEPARTURE_TIME>
<ARRIVAL_DATE>2014-06-05</ARRIVAL_DATE>
<ARRIVAL_TIME>2130</ARRIVAL_TIME>
<ARRIVAL_AIRPORT>P1</ARRIVAL_AIRPORT>
</document>
</AIRPORTSFILE>
The output needs to be:
<catalog>
<document name="SAMPLE1">
<departureDate>2014-03-15,2014-03-14</departureDate>
<arrivalAirport>A1,A2</arrivalAirport>
</document>
<document name="SAMPLE2">
<departureDate>2014-06-05,2014-06-06</departureDate>
<arrivalAirport>P1</arrivalAirport>
</document>
</catalog>
I have looked at XSLT 1.0 - Remove Duplicate Nodes From Variable and XSLT 1.0 - Remove duplicates fields for some reference, but cannot get it to work properly.
Below is what I have in my xsl 1.0 file to get DEPARTURE_DATE to work.
<xsl:key name="kDepartureDate" match="DEPARTURE_DATE" use="."/>
<xsl:template match="@* | node()" name="Copy">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="DEPARTURE_DATE[generate-id() =
generate-id(key('kDepartureDate', .)[1])]" name="depDateCopy">
<xsl:call-template name="Copy" />
</xsl:template>
<xsl:template match="AIRPORTSFILE">
<catalog>
<xsl:for-each select="document">
<xsl:variable name="departureDate">
<xsl:call-template name="depDateCopy"></xsl:call-template>
</xsl:variable>
</xsl:for-each>
</catalog>
</xsl:template>
Any help will be much appreciated.
<catalog>
element in the template matchingAIRPORTSFILE
. – michael.hor257k