XSL分组问题

时间:2015-06-02 10:27:19

标签: xml xslt

我面临的问题是将元素分组为空白而没有输出。我想将所有位置名称相同的货物分组,例如。

将PPGNA.00055396和PPGNA.00055397组合在一起,并将PPGNA.00055473和PPGNA.00055472分开,因为它们共享相同的位置名称

下面的

是xml

的xml:

 <?xml version="1.0" encoding="UTF-8"?>
 <notify>
<Subject>Consolidated Tender Event Notification</Subject>
<Severity>Information</Severity>
<Contact ID="to">
    <FirstName>FXNL</FirstName>
    <LastName>TENDER</LastName>
    <Company>FEDEX NATIONAL (LTL) (FXNL)</Company>
    <LocationID>FXNL</LocationID>
    <Phone/>
    <Fax/>
           <Role/>
</Contact>
<contents>
    <content>
        <subject>PICKUP</subject>
        <shipment_gid>PPGNA.00055396</shipment_gid>
        <i_transaction_no>1693450</i_transaction_no>
        <tender_record>
            <bm_refnum>00055396</bm_refnum>
            <tender_status>PICKUP NOTIFICATION</tender_status>
            <response_time TZ="America/New_York">2015-06-02 19:19:28</response_time>
            <number_of_stops>2</number_of_stops>
            <total_weight IN="LB">9975.0</total_weight>
            <total_volume IN="CUFT">0.0</total_volume>
            <total_ship_unit_count>1</total_ship_unit_count>
            <stops>
                <stop>
                    <stop_num>2</stop_num>
                    <planned_arrival TZ="America/New_York">2015-05-26 12:00:00</planned_arrival>
                    <planned_departure TZ="America/New_York">2015-05-26 12:29:57</planned_departure>
                    <location_xid>FGL-03520000</location_xid>
                    <location_name>SHL</location_name>
                    <city>SHELBY</city>
                    <province/>
                    <province_code>NC</province_code>
                    <zip_code>28150</zip_code>
                    <country_code>US</country_code>
                </stop>
                <stop>
                    <stop_num>1</stop_num>
                    <planned_arrival TZ="America/Chicago">2015-05-21 13:00:00</planned_arrival>
                    <planned_departure TZ="America/Chicago">2015-05-21 13:29:57</planned_departure>
                    <location_xid>FGLSUP-11111113</location_xid>
                    <location_name>MOMENTIVE SPECIALTY CHEMICALS</location_name>
                    <city>BEDFORD PARK</city>
                    <province/>
                    <province_code>IL</province_code>
                    <zip_code>60501</zip_code>
                    <country_code>US</country_code>
                </stop>
            </stops>
            <start_time TZ="America/New_York">2015-05-21 13:00:00</start_time>
            <end_time TZ="America/Chicago">2015-05-26 12:29:57</end_time>
            <equipments>
                <equipment>
                    <equipment_xid>77661</equipment_xid>
                    <equipment_type_xid/>
                    <equipment_type_name/>
                    <equipment_group_xid>28RT_VAN_TEMPCONTROL</equipment_group_xid>
                    <equipment_group_name>28FT_TEMPCONTROL_VAN</equipment_group_name>
                </equipment>
            </equipments>
            <remarks>
                <remark>
                    <remark_qual_gid>LTL_SOURCE_ADDRESS</remark_qual_gid>
                    <remark_text>8600 WEST 71ST STREET</remark_text>
                </remark>
                <remark>
                    <remark_qual_gid>DELIVERY_INSTRUCTIONS_LINE_1</remark_qual_gid>
                    <remark_text>NONE</remark_text>
                </remark>
                <remark>
                    <remark_qual_gid>LTL_DEST_ADDRESS</remark_qual_gid>
                    <remark_text>940 WASHBURN SWITCH ROAD</remark_text>
                </remark>
                <remark>
                    <remark_qual_gid>LTL_TOTAL_PALLET_COUNT</remark_qual_gid>
                    <remark_text>0</remark_text>
                </remark>
            </remarks>
        </tender_record>

        <Type>TENDER</Type>
    </content>
    <content>
        <subject>PICKUP</subject>
        <shipment_gid>PPGNA.00055397</shipment_gid>
        <i_transaction_no>1693451</i_transaction_no>
        <tender_record>
            <bm_refnum>00055397</bm_refnum>
            <tender_status>PICKUP NOTIFICATION</tender_status>
            <response_time TZ="America/New_York">2015-06-02 19:19:52</response_time>
            <number_of_stops>2</number_of_stops>
            <total_weight IN="LB">9975.0</total_weight>
            <total_volume IN="CUFT">0.0</total_volume>
            <total_ship_unit_count>1</total_ship_unit_count>
            <stops>
                <stop>
                    <stop_num>1</stop_num>
                    <planned_arrival TZ="America/Chicago">2015-05-21 13:00:00</planned_arrival>
                    <planned_departure TZ="America/Chicago">2015-05-21 13:29:57</planned_departure>
                    <location_xid>FGLSUP-11111113</location_xid>
                    <location_name>MOMENTIVE SPECIALTY CHEMICALS</location_name>
                    <city>BEDFORD PARK</city>
                    <province/>
                    <province_code>IL</province_code>
                    <zip_code>60501</zip_code>
                    <country_code>US</country_code>
                </stop>
                <stop>
                    <stop_num>2</stop_num>
                    <planned_arrival TZ="America/New_York">2015-05-26 12:00:00</planned_arrival>
                    <planned_departure TZ="America/New_York">2015-05-26 12:29:57</planned_departure>
                    <location_xid>FGL-03520000</location_xid>
                    <location_name>SHL</location_name>
                    <city>SHELBY</city>
                    <province/>
                    <province_code>NC</province_code>
                    <zip_code>28150</zip_code>
                    <country_code>US</country_code>
                </stop>
            </stops>
            <start_time TZ="America/Chicago">2015-05-21 13:00:00</start_time>
            <end_time TZ="America/New_York">2015-05-26 12:29:57</end_time>
            <equipments>
                <equipment>
                    <equipment_xid>77662</equipment_xid>
                    <equipment_type_xid/>
                    <equipment_type_name/>
                    <equipment_group_xid>28RT_VAN_TEMPCONTROL</equipment_group_xid>
                    <equipment_group_name>28FT_TEMPCONTROL_VAN</equipment_group_name>
                </equipment>
            </equipments>
            <remarks>
                <remark>
                    <remark_qual_gid>LTL_SOURCE_ADDRESS</remark_qual_gid>
                    <remark_text>8600 WEST 71ST STREET</remark_text>
                </remark>
                <remark>
                    <remark_qual_gid>DELIVERY_INSTRUCTIONS_LINE_1</remark_qual_gid>
                    <remark_text>NONE</remark_text>
                </remark>
                <remark>
                    <remark_qual_gid>LTL_TOTAL_PALLET_COUNT</remark_qual_gid>
                    <remark_text>0</remark_text>
                </remark>
                <remark>
                    <remark_qual_gid>LTL_DEST_ADDRESS</remark_qual_gid>
                    <remark_text>940 WASHBURN SWITCH ROAD</remark_text>
                </remark>
            </remarks>
        </tender_record>

        <Type>TENDER</Type>
    </content>
    <content>
        <subject>PICKUP</subject>
        <shipment_gid>PPGNA.00055473</shipment_gid>
        <i_transaction_no>1693453</i_transaction_no>
        <tender_record>
            <bm_refnum>00055473</bm_refnum>
            <tender_status>PICKUP NOTIFICATION</tender_status>
            <response_time TZ="America/New_York">2015-06-02 19:21:10</response_time>
            <number_of_stops>2</number_of_stops>
            <total_weight IN="LB">8000.0</total_weight>
            <total_volume IN="CUFT">0.0</total_volume>
            <total_ship_unit_count>1</total_ship_unit_count>
            <stops>
                <stop>
                    <stop_num>1</stop_num>
                    <planned_arrival TZ="America/New_York">2015-05-28 09:22:45</planned_arrival>
                    <planned_departure TZ="America/New_York">2015-05-28 10:22:45</planned_departure>
                    <location_xid>PGL-0306</location_xid>
                    <location_name>WORKS 6 PPG INDUSTRIES INC.</location_name>
                    <city>CARLISLE</city>
                    <province/>
                    <province_code>PA</province_code>
                    <zip_code>17065</zip_code>
                    <country_code>US</country_code>
                </stop>
                <stop>
                    <stop_num>2</stop_num>
                    <planned_arrival TZ="America/New_York">2015-06-01 12:00:00</planned_arrival>
                    <planned_departure TZ="America/New_York">2015-06-01 12:00:00</planned_departure>
                    <location_xid>PGLSU-11111121</location_xid>
                    <location_name>MATERIAL SCIENCE</location_name>
                    <city>COLUMBUS</city>
                    <province/>
                    <province_code>OH</province_code>
                    <zip_code>43228</zip_code>
                    <country_code>US</country_code>
                </stop>
            </stops>
            <start_time TZ="America/New_York">2015-05-28 09:22:45</start_time>
            <end_time TZ="America/New_York">2015-06-01 12:00:00</end_time>
            <equipments>
                <equipment>
                    <equipment_xid>77849</equipment_xid>
                    <equipment_type_xid/>
                    <equipment_type_name/>
                    <equipment_group_xid>28CV_VAN</equipment_group_xid>
                    <equipment_group_name>28FT_VAN</equipment_group_name>
                </equipment>
            </equipments>
            <remarks>
                <remark>
                    <remark_qual_gid>DELIVERY_INSTRUCTIONS_LINE_1</remark_qual_gid>
                    <remark_text>NONE</remark_text>
                </remark>
                <remark>
                    <remark_qual_gid>LTL_SOURCE_ADDRESS</remark_qual_gid>
                    <remark_text>400 PARK DRIVE</remark_text>
                </remark>
                <remark>
                    <remark_qual_gid>LTL_DEST_ADDRESS</remark_qual_gid>
                    <remark_text>1660 Georgesville Rd</remark_text>
                </remark>
                <remark>
                    <remark_qual_gid>LTL_TOTAL_PALLET_COUNT</remark_qual_gid>
                    <remark_text>0</remark_text>
                </remark>
            </remarks>
        </tender_record>

        <Type>TENDER</Type>
    </content>
    <content>
        <subject>PICKUP</subject>
        <shipment_gid>PPGNA.00055472</shipment_gid>
        <i_transaction_no>1693455</i_transaction_no>
        <tender_record>
            <bm_refnum>00055472</bm_refnum>
            <tender_status>PICKUP NOTIFICATION</tender_status>
            <response_time TZ="America/New_York">2015-06-02 19:21:43</response_time>
            <number_of_stops>2</number_of_stops>
            <total_weight IN="LB">8000.0</total_weight>
            <total_volume IN="CUFT">0.0</total_volume>
            <total_ship_unit_count>1</total_ship_unit_count>
            <stops>
                <stop>
                    <stop_num>1</stop_num>
                    <planned_arrival TZ="America/New_York">2015-05-28 09:20:20</planned_arrival>
                    <planned_departure TZ="America/New_York">2015-05-28 10:20:20</planned_departure>
                    <location_xid>PGL-0306</location_xid>
                    <location_name>WORKS 6 PPG INDUSTRIES INC.</location_name>
                    <city>CARLISLE</city>
                    <province/>
                    <province_code>PA</province_code>
                    <zip_code>17065</zip_code>
                    <country_code>US</country_code>
                </stop>
                <stop>
                    <stop_num>2</stop_num>
                    <planned_arrival TZ="America/New_York">2015-06-01 12:00:00</planned_arrival>
                    <planned_departure TZ="America/New_York">2015-06-01 12:00:00</planned_departure>
                    <location_xid>PGLSU-11111121</location_xid>
                    <location_name>MATERIAL SCIENCE</location_name>
                    <city>COLUMBUS</city>
                    <province/>
                    <province_code>OH</province_code>
                    <zip_code>43228</zip_code>
                    <country_code>US</country_code>
                </stop>
            </stops>
            <start_time TZ="America/New_York">2015-05-28 09:20:20</start_time>
            <end_time TZ="America/New_York">2015-06-01 12:00:00</end_time>
            <equipments>
                <equipment>
                    <equipment_xid>77848</equipment_xid>
                    <equipment_type_xid/>
                    <equipment_type_name/>
                    <equipment_group_xid>28CV_VAN</equipment_group_xid>
                    <equipment_group_name>28FT_VAN</equipment_group_name>
                </equipment>
            </equipments>
            <remarks>
                <remark>
                    <remark_qual_gid>DELIVERY_INSTRUCTIONS_LINE_1</remark_qual_gid>
                    <remark_text>NONE</remark_text>
                </remark>
                <remark>
                    <remark_qual_gid>LTL_TOTAL_PALLET_COUNT</remark_qual_gid>
                    <remark_text>0</remark_text>
                </remark>
                <remark>
                    <remark_qual_gid>LTL_SOURCE_ADDRESS</remark_qual_gid>
                    <remark_text>400 PARK DRIVE</remark_text>
                </remark>
                <remark>
                    <remark_qual_gid>LTL_DEST_ADDRESS</remark_qual_gid>
                    <remark_text>1660 Georgesville Rd</remark_text>
                </remark>
            </remarks>
        </tender_record>

        <Type>TENDER</Type>
    </content>
</contents>
<Locale>
    <Language>en</Language>
    <Country>US</Country>
    <Variant/>
  </Locale>
 </notify> 

和xsl使用

&#13;
&#13;
        <?xml version="1.0" encoding="UTF-8"?>
        <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
         <!--added code for key-->
         <xsl:key name="stops" match="contents/content" use="location_name" />
          <html>
          <body bgcolor="ffffff" vlink="gray" link="#0000cd" marginwidth="10" marginheight="10" leftmargin="10" topmargin="10">
			<table width="658" cellpadding="2">
				<tr>
					<td colspan="2">
						<img alt="" src=""/>
					</td>
				</tr>
				<tr>
					<td colspan="2" style="vertical-align: top; font-family: Verdana, Arial, Helvetica; font-size: 16px; ">
						<xsl:value-of select="Contact[@ID='to']/Company"/>
					</td>
				</tr>
				<tr>
					<td colspan="2" style="vertical-align: top; font-family: Verdana, Arial, Helvetica; font-size: 28px; font-weight: bold; color: #000000;">
						Oracle Transportation Management<br/>
						Consolidated Pickup Notification
					</td>
				</tr>
				<tr>
					<td style="vertical-align: top; font-family: Verdana, Arial, Helvetica; font-size: 12px; font-weight: bold;">
						Please see below for a listing of Shipments due for Pickup, or that have been cancelled.
					</td>
				</tr>
				<tr>
					<td></td>
				</tr>
			</table>
<!--Modifying the XSL code for consolidation Sequence below -->

						<xsl:for-each select="contents/content[count(. | key('stops', location_name)[1]) = 1]">
                                       <xsl:sort select="location_name" />
				<xsl:for-each select="key('stops',location_name)">
           <xsl:sort select="shipment_gid"/>


					  
							 				<table width="658" cellpadding="3" style="border-spacing: 4px 0px;">
											
								
					<xsl:choose>
													<xsl:when test="subject='PICKUP_CANCEL'">
													<tr>
								<td style="color:#E26B0A;  font-size: 16px; font-family: Verdana, Arial, Helvetica; font-style:italic; font-weight: bold;" colspan="5">
									Pickup Cancel
								</td>
							</tr>
							<tr style="background-color:#fabf8f; font-weight:bold; vertical-align: bottom; font-family: Verdana, Arial, Helvetica; font-size: 12px; ">
								<td>Shipment ID</td>
								<td>Start Time</td>
								<td>Total Weight</td>
								<td>Total Volume</td>
								<td>Pallet Count</td>
							</tr>
							<tr style="background-color:#fde9d9; font-family: Verdana, Arial, Helvetica; font-size: 12px; ">
								<td><xsl:value-of select="shipment_gid"/></td>
								<td><xsl:value-of select="tender_record/start_time"/></td>
								<td><xsl:value-of select="tender_record/total_weight"/></td>
								<td><xsl:value-of select="tender_record/total_volume"/></td>
								<td><xsl:value-of select="tender_record/remarks/remark[remark_qual_gid='LTL_TOTAL_PALLET_COUNT']/remark_text"/></td>
							</tr>
						</xsl:when>
						<xsl:otherwise>
							<tr>
								<td style="color:#366092;  font-size: 16px; font-family: Verdana, Arial, Helvetica; font-style:italic; font-weight: bold;" colspan="5">
									Pickup
								</td>
							</tr>
							<tr style="background-color:#538dd5; font-weight:bold; vertical-align: bottom; font-family: Verdana, Arial, Helvetica; font-size: 12px; ">
								<td>Shipment ID</td>
								<td>Start Time</td>
								<td>Total Weight</td>
								<td>Total Volume</td>
								<td>Pallet Count</td>
							</tr>
							<tr style="background-color:#c5d9f1; font-family: Verdana, Arial, Helvetica; font-size: 12px; ">
								<td><xsl:value-of select="shipment_gid"/></td>
								<td><xsl:value-of select="tender_record/start_time"/></td>
								<td><xsl:value-of select="tender_record/total_weight"/></td>
								<td><xsl:value-of select="tender_record/total_volume"/></td>
								<td><xsl:value-of select="tender_record/remarks/remark[remark_qual_gid='LTL_TOTAL_PALLET_COUNT']/remark_text"/></td>
							</tr>
						</xsl:otherwise>
					 </xsl:choose>
										
					<tr>
						<td></td>
					</tr>
					<tr>
						<td colspan="5" style="background-color:#bfbfbf; font-family: Verdana, Arial, Helvetica; font-size: 12px; ">
							Special Instructions: <xsl:value-of select ="tender_record/remarks/remark[remark_qual_gid='DELIVERY_INSTRUCTIONS_LINE_1']/remark_text"/>
						</td>
					</tr>
					<tr>
						<td></td>
					</tr>
					
					<tr style="background-color:#f2f2f2;">
						<td colspan="5">
							<table  width="658" cellpadding="0" style="vertical-align: top; font-family: Verdana, Arial, Helvetica; font-size: 12px;">
														<tr>
									<td>
										<span style="font-weight: bold">Pickup</span><br/>
										<xsl:value-of select="tender_record/stops/stop[stop_num=1]/location_name"/><br/>
										<xsl:value-of select="tender_record/remarks/remark[remark_qual_gid='LTL_SOURCE_ADDRESS']/remark_text"/><br/>
										<xsl:value-of select="tender_record/stops/stop[stop_num=1]/city"/><xsl:text>,&#160;</xsl:text>
										<xsl:value-of select="tender_record/stops/stop[stop_num=1]/province_code"/><xsl:text>&#160;</xsl:text>
										<xsl:value-of select="tender_record/stops/stop[stop_num=1]/zip_code"/><xsl:text>&#160;</xsl:text>
										<xsl:value-of select="tender_record/stops/stop[stop_num=1]/country_code"/>
									</td>
									<td>
										<span style="font-weight: bold">Delivery</span><br/>
										<xsl:value-of select="tender_record/stops/stop[stop_num=2]/location_name"/><br/>
										<xsl:value-of select="tender_record/remarks/remark[remark_qual_gid='LTL_DEST_ADDRESS']/remark_text"/><br/>
										<xsl:value-of select="tender_record/stops/stop[stop_num=2]/city"/><xsl:text>,&#160;</xsl:text>
										<xsl:value-of select="tender_record/stops/stop[stop_num=2]/province_code"/><xsl:text>&#160;</xsl:text>
										<xsl:value-of select="tender_record/stops/stop[stop_num=2]/zip_code"/><xsl:text>&#160;</xsl:text>
										<xsl:value-of select="tender_record/stops/stop[stop_num=2]/country_code"/>
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td></td>
					</tr>
					<xsl:choose>
						<xsl:when test="subject='PICKUP_CANCEL'">
							<tr style="background-color:#fabf8f; font-weight:bold; vertical-align: bottom; font-family: Verdana, Arial, Helvetica; font-size: 12px;">
								<td>Line Item</td>
								<td>Haz Info</td>
								<td>Weight</td>
								<td>Handling Units</td>
								<td>Pallet Count</td>
							</tr>
						</xsl:when>
						<xsl:otherwise>
							<tr style="background-color:#538dd5; font-weight:bold; vertical-align: bottom; font-family: Verdana, Arial, Helvetica; font-size: 12px;">
								<td>Line Item</td>
								<td>Haz Info</td>
								<td>Weight</td>
								<td>Handling Units</td>
								<td>Pallet Count</td>
							</tr>
						</xsl:otherwise>
					</xsl:choose>
					<xsl:for-each select="tender_record/remarks/remark[remark_qual_gid='LTL_LINE_INFO']">
						<xsl:choose>
							<xsl:when test="subject='PICKUP_CANCEL'">
								<tr style="background-color:#c5d9f1; font-family: Verdana, Arial, Helvetica; font-size: 12px;">
									<td>
										<xsl:value-of select="remark_text" disable-output-escaping="yes" />
									</td>
								</tr>
							</xsl:when>
							<xsl:otherwise>
								<tr style="background-color:#fde9d9; font-family: Verdana, Arial, Helvetica; font-size: 12px;">
									<td>
										<xsl:value-of select="remark_text" disable-output-escaping="yes" />
									</td>
								</tr>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:for-each>
					<tr>
						<td></td>
					</tr>
					<tr>
						<td></td>
					</tr>
				</table>
			</xsl:for-each>
                       </xsl:for-each>
				<table width="658" cellpadding="2">
					<tr>
						<td style="vertical-align: top; font-family: Verdana, Arial, Helvetica; font-size: 12px; font-style: italic;">
                                 test						
								 </td>
					</tr>
				</table>
                          </body>
                        </html>
                  </xsl:template>
                </xsl:stylesheet>
&#13;
&#13;
&#13;

0 个答案:

没有答案