Sorry, didn't even notice that - some copy& paste "feature"
Iâm trying to obtain the following output:
Code:
<?xml version="1.0" encoding="utf-8"?>
<TripXML xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<TripSection>
<Detail SegNum="2" From="GIG" To="PTY" TripItem="1" />
<Detail SegNum="4" From="PTY" To="BOG" TripItem="2" />
<Detail SegNum="8" From="LIM" To="SCL" TripItem="4" />
<Detail SegNum="10" From="SCL" To="GIG" TripItem="5" />
</TripSection>
</TripXML>
From the following input:
Code:
<?xml version="1.0" encoding="utf-8"?>
<Trip>
<FlightSection>
<Flight SegNbr="002" OrigAir="GIG" DestAir="PTY" />
<Flight SegNbr="004" OrigAir="PTY" DestAir="BOG" />
<Flight SegNbr="008" OrigAir="LIM" DestAir="SCL" />
<Flight SegNbr="010" OrigAir="SCL" DestAir="GIG" />
</FlightSection>
</Trip>
There is no Tripitem 3 as the âToâ on SegNum 4 differs to the âFromâ on SegNum 8 (i.e. an unknown trip to get from âBOGâ to âLIMâ - & I know it could be more than 1, but thatâs not an issue)
Within main template I have this:
Code:
<xsl:attribute name="TripItem">
<xsl:call-template name="GetTripItem">
<xsl:with-param name="thisSeg" select="number(@SegNbr)"/>
<xsl:with-param name="lastSeg" select="0"/>
<xsl:with-param name="previousDest" select="***"/>
<xsl:with-param name="previousCoupon" select="0"/>
</xsl:call-template>
</xsl:attribute>
& the GetTripItem template is as follows:
Code:
<xsl:template name="GetTripItem">
<xsl:param name="thisSeg" />
<xsl:param name="lastSeg" />
<xsl:param name="previousDest" />
<xsl:param name="previousCoupon" />
<xsl:for-each select="/Trip/FlightSection/Flight[number(@SegNbr) > $lastSeg]">
<xsl:choose>
<xsl:when test="number(@SegNbr) = $thisSeg">
<xsl:value-of select="$previousCoupon + 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:if test="@OrigAir = $previousDest or $previousDest = '***'" >
<xsl:call-template name="GetTripItem">
<xsl:with-param name="thisSeg" select="$thisSeg" />
<xsl:with-param name="lastSeg" select="number(@SegNbr)"/>
<xsl:with-param name="previousDest" select="@DestAir" />
<xsl:with-param name="previousCoupon" select="$previousCoupon + 1"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="@OrigAir != $previousDest">
<xsl:call-template name="GetTripItem">
<xsl:with-param name="thisSeg" select="$thisSeg" />
<xsl:with-param name="lastSeg" select="number(@SegNbr)"/>
<xsl:with-param name="previousDest" select="@DestAir" />
<xsl:with-param name="previousCoupon" select="$previousCoupon + 2"/>
</xsl:call-template>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
This however gives me:
Code:
<?xml version="1.0" encoding="utf-8"?>
<TripXML xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<TripSection>
<Detail SegNum="2" From="GIG" To="PTY" TripItem="1" />
<Detail SegNum="4" From="PTY" To="BOG" TripItem="31" />
<Detail SegNum="8" From="LIM" To="SCL" TripItem="4331" />
<Detail SegNum="10" From="SCL" To="GIG" TripItem="64535331" />
</TripSection>
</TripXML>
It appears (to me) that as each recursive call is doing a for-each, the more flights the more characters in the TripItem