Chris Daniel has asked for the wisdom of the Perl Monks concerning the following question:
Hi All,
I have some issues in XSLT conversion. I have xml with multple <PortDetails> tag.
<PortDetails> <PortType>A</PortType> <PortCode>USBAL</PortCode> <CutOffDate>2016-09-28</CutOffDate> <CutOffTime>12:00</CutOffTime> </PortDetails> <PortDetails> <PortType>L</PortType> <PortCode>USMIA</PortCode> <ETD>2016-10-13</ETD> </PortDetails>
Now I want to convert this as below:
<RoutingDetails> <StageQualifier>1</StageQualifier> (If PortType is A) <TransportMode>1</TransportMode> (If PortType is A) <TransportName>TRUCK</TransportName> (If PortType is A) <Origin>ESBCN</Origin> (If PortType is A) <ETD>2017-01-03 00:00:00 GMT</ETD> (If PortType is A) <Destination>ESBCN</Destination> (If PortType is L) <ETA>2017-01-20</ETA> (If PortType is L) </RoutingDetails>
Actually I need to merge the content of two PortDetails into one <RoutingDetails>
I have tried the below xsl
<xsl:for-each select="ScheduleDetails/PortDetails"> <xsl:choose> <xsl:when test="PortType[text()='A' or text()='L']"> <RoutingDetails> <xsl:if test="PortType ='A'"> <StageQualifier>1</StageQualifier> <TransportMode>6</TransportMode> <TransportName>NV PRECARRIAGE</TransportName> <Origin><xsl:value-of select="PortCode"/></Origin> <ETD><xsl:value-of select="CutOffDate"/></ETD> </xsl:if> <xsl:if test="PortType ='L'"> <Destination><xsl:value-of select="PortCode"/></Destination> <ETA><xsl:value-of select="ETD"/></ETA> </xsl:if> </RoutingDetails> </xsl:when> </xsl:choose> </xsl:for-each>
But output is not as per required one:
<RoutingDetails> <StageQualifier>1</StageQualifier> <TransportMode>6</TransportMode> <TransportName>NV PRECARRIAGE</TransportName> <Origin>USBAL</Origin> <ETD>2016-09-28</ETD> </RoutingDetails> <RoutingDetails> <Destination>USMIA</Destination> <ETA>2016-10-13</ETA> </RoutingDetails>
All I need to to have this data into single <RoutingDetails>. Please help on this.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Conversion of Files Using XSLT
by choroba (Cardinal) on Dec 14, 2016 at 10:42 UTC | |
|
Re: Conversion of Files Using XSLT
by Corion (Patriarch) on Dec 14, 2016 at 09:23 UTC | |
by Chris Daniel (Novice) on Dec 14, 2016 at 09:52 UTC | |
by Corion (Patriarch) on Dec 14, 2016 at 09:53 UTC | |
by hippo (Archbishop) on Dec 14, 2016 at 10:00 UTC | |
by Chris Daniel (Novice) on Dec 14, 2016 at 10:19 UTC | |
by Corion (Patriarch) on Dec 14, 2016 at 10:24 UTC | |
|
Re: Conversion of Files Using XSLT
by choroba (Cardinal) on Dec 14, 2016 at 09:23 UTC | |
by Chris Daniel (Novice) on Dec 14, 2016 at 10:15 UTC |