I am working with a marketing platform to display the Bags that a person has ordered for a flight. One Passenger can have multiple Segments as part of an overall Journey. So if we have records like below (each record has a unique value assigned as well since this is all inserted into a database before being pulled out, the xml here is a mockup of what im working with).
Edit 8/9 - Actual XML and revised XSLT below. Also if you look at this link (http://f.spiritairlines.com/ats/msg.aspx?sg1=2e4a4d00cb00be84c598b618d6556e3e) in the Bag section. I want it to look like the second line (Pedro Smith) and not the first line (Sandra Smith). By the way this is all test data so there is no privacy concerns with showing you nor is there any private info on their.
<bookingcontact_to_booking>
<passenger_to_bookings>
<passenger_to_booking>
<Prop pk_id="4147" entity_id="126" val="SMITH" type_id="20" prop_name="lastname" prop_id="10208"/>
<Prop pk_id="4147" entity_id="126" val="PEDRO" type_id="20" prop_name="firstname" prop_id="10206"/>
<passseg_to_passengers>
<passseg_to_passenger>
<Prop pk_id="9432" entity_id="122" val="2013-08-27 17:45:00.000" type_id="30" prop_name="arrivaltime" prop_id="10216"/>
<Prop pk_id="9432" entity_id="122" val="188" type_id="20" prop_name="flightnumber" prop_id="10217"/>
<Prop pk_id="9432" entity_id="122" val="5" type_id="10" prop_name="checkedbagcount" prop_id="10220"/>
<Prop pk_id="9432" entity_id="122" val="1" type_id="10" prop_name="carryonbagcount" prop_id="10221"/>
<Prop pk_id="9432" entity_id="122" val="1" type_id="10" prop_name="journeynumber" prop_id="10222"/>
<Prop pk_id="9432" entity_id="122" val="0" type_id="10" prop_name="segmentnumber" prop_id="10223"/>
<Prop pk_id="9432" entity_id="122" val="2013-08-27 08:12:00.000" type_id="30" prop_name="departuretime" prop_id="10296"/>
<Prop pk_id="9432" entity_id="122" val="Las Vegas, NV" type_id="20" prop_name="departureairport" prop_id="10297"/>
<Prop pk_id="9432" entity_id="122" val="New York, NY - LaGuardia " type_id="20" prop_name="arrivalairport" prop_id="10298"/>
<Prop pk_id="9432" entity_id="122" val="10B,20B" type_id="20" prop_name="seatassignment" prop_id="10299"/>
</passseg_to_passenger>
<passseg_to_passenger>
<Prop pk_id="9433" entity_id="122" val="10B,20B" type_id="20" prop_name="seatassignment" prop_id="10299"/>
<Prop pk_id="9433" entity_id="122" val="Fort Lauderdale, FL" type_id="20" prop_name="arrivalairport" prop_id="10298"/>
<Prop pk_id="9433" entity_id="122" val="New York, NY - LaGuardia " type_id="20" prop_name="departureairport" prop_id="10297"/>
<Prop pk_id="9433" entity_id="122" val="2013-08-27 19:45:00.000" type_id="30" prop_name="departuretime" prop_id="10296"/>
<Prop pk_id="9433" entity_id="122" val="1" type_id="10" prop_name="segmentnumber" prop_id="10223"/>
<Prop pk_id="9433" entity_id="122" val="1" type_id="10" prop_name="journeynumber" prop_id="10222"/>
<Prop pk_id="9433" entity_id="122" val="1" type_id="10" prop_name="carryonbagcount" prop_id="10221"/>
<Prop pk_id="9433" entity_id="122" val="5" type_id="10" prop_name="checkedbagcount" prop_id="10220"/>
<Prop pk_id="9433" entity_id="122" val="779" type_id="20" prop_name="flightnumber" prop_id="10217"/>
<Prop pk_id="9433" entity_id="122" val="2013-08-27 22:45:00.000" type_id="30" prop_name="arrivaltime" prop_id="10216"/>
</passseg_to_passenger>
</passseg_to_passengers>
</passenger_to_booking>
</passenger_to_bookings>
</bookingcontact_to_booking>
I want to only display the CarryOnBagCount and CheckedBagCount once per journey. I have tried a few different methods, but i think i am getting further from the solution. At the moment the output is all bagcounts regardless of journey and segment. XSLT is below.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" indent="yes" omit-xml-declaration="yes" />
<xsl:key name="journey" match="passengersegment" use="Prop[@prop_name = 'journeynumber']/@val"/>
<xsl:template match="/">
<xsl:for-each select="/Msg/Props/bookingcontact_to_booking/passenger_to_bookings/passenger_to_booking">
<tr>
<td colspan="3">
<table style="text-align: left; line-height: 18px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; color:#333333;"
border="0" cellspacing="0" cellpadding="0" width="542" align="left">
<tbody>
<tr>
<td height="22" width="200">
<xsl:value-of select="Prop[@prop_name = 'firstname']/@val" /><xsl:text> </xsl:text><xsl:value-of select="Prop[@prop_name = 'lastname']/@val" />
</td>
<xsl:apply-templates select="passengersegment[generate-id() = generate-id(key('journey', journeynumber)[1])]"/>
</tr>
</tbody>
</table>
</td>
</tr>
</xsl:for-each>
</xsl:template>
<xsl:template match="passengersegment">
<td style="text-align: left;" width="100">
<table style="text-align: left; line-height: 18px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; color:#333333;" width="100">
<tr>
<xsl:for-each select="passseg_to_passengers/passseg_to_passenger">
<td width="50">
<xsl:value-of select="Prop[@prop_name = 'carryonbagcount']/@val" />
</td>
</xsl:for-each>
</tr>
</table>
</td>
<td style="text-align: left;" width="100">
<table style="text-align: left; line-height: 18px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; color:#333333;" width="100">
<tr>
<xsl:for-each select="passseg_to_passengers/passseg_to_passenger">
<td width="50">
<xsl:value-of select="Prop[@prop_name = 'checkedbagcount']/@val" />
</td>
</xsl:for-each>
</tr>
</table>
</td>
</xsl:template>
</xsl:stylesheet>
It's a bit tricky to give a precise answer without seeing a sample of your expected HTML, and also because the element names in your XSLT don't seem to match up with your input XML sample. However, the technique you need to be reading up about and using here is Muenchian Grouping. This is the most efficient way of grouping elements in XSLT 1.0.
In your case, you want to get the distinct journeys for the passenger, and then get the first segment for each one. You do this by defining a key to lookup the passengersegment elements by their journeynumber
<xsl:key name="journey" match="passengersegment" use="journeynumber"/>
Then, to get the distinct journey numbers, you look at all passengersegment but only select the ones that occur first in the key for their given journeynumber value.
<xsl:apply-templates
select="passengersegment
[generate-id() = generate-id(key('journey', journeynumber)[1])]"/>
Within the template that matches passengersegment you can then output the first carryonbagcount and checkednbagcount for the segment (the first in the journey).
Try this XSLT as a start, and build on this:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:key name="journey" match="passengersegment" use="journeynumber"/>
<xsl:template match="/passenger">
<table border="1">
<tr>
<th>Journey</th>
<th>Carry on</th>
<th>Checked</th>
</tr>
<xsl:apply-templates select="passengersegment[generate-id() = generate-id(key('journey', journeynumber)[1])]"/>
</table>
</xsl:template>
<xsl:template match="passengersegment">
<tr>
<td>
<xsl:value-of select="journeynumber"/>
</td>
<td>
<xsl:value-of select="carryonbagcount"/>
</td>
<td>
<xsl:value-of select="checkedbagcount"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
Note that if wanted to get the total carryonbagcount for all segments in the journey, then within the passengersegment you could do something like this:
<xsl:value-of select="sum(key('journey', journeynumber)/carryonbagcount)" />