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.


In reply to Conversion of Files Using XSLT by Chris Daniel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.