0

我需要使用 XSLT 显示来自 web 服务的 XML,但我试图在 XML 文件中循环,它只显示第一行。请告诉我在每个 xslt 循环中我做错了什么。

我的 xml 表很长,出于示例目的,我只提供一行数据。

<?xml-stylesheet type="text/xsl" href="XSLTFile.xsl"?>
 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
       <ns1:OTA_AirLowFareSearchRS Version="2.001" xmlns="http://www.opentravel.org/OTA/2003/05" xmlns:ns1="http://www.opentravel.org/OTA/2003/05">
           <ns1:Success />
           <ns1:PricedItineraries>
             <ns1:PricedItinerary CompositeFlightNumber="AI" CountCompositeFlightNumber="1" FareType="Non-Refundable" InboundSegmentReference="1" MatrixFare="true" Mode="" OriginDestinationRPH="BLRHYDAI517AI20130321" OutboundSegmentReference="1" Priority="1" RecommendationRPH="1" Refundable="true" ReturnOnly="false" SequenceNumber="1.0" SupplierCode="1AWS">
               <ns1:AirItinerary SupplierSystem="Amadeus">
                 <ns1:OriginDestinationOptions>
                   <ns1:OriginDestinationOption Duration="01:05:00" FlightID="BLRHYDAI517AI2013-03-21" MajorityCarrier="AI" ReturnOnly="false" SupplierCode="1AWS" SupplierSystem="Amadeus" UniqueIdentifier="1.0">
                     <ns1:FlightSegment ArrivalDateTime="2013-03-21T09:20:00" CabinCode="Y" DeliveryMethod="Courier" DepartureDateTime="2013-03-21T08:15:00" Duration="01:05:00" FlightNumber="517" LTD="1AWS" LineNumber="Y" NumberInParty="BLRHYD" RPH="1" ResBookDesigCode="E" TicketType="Physical" ValidConnectionInd="1AWS">
                       <ns1:DepartureAirport AirPortName="Bengaluru" CityName="Bangalore" LocationCode="BLR" />
                       <ns1:ArrivalAirport AirPortName="Shamshabad Rajiv Gandhi" CityName="Hyderabad" LocationCode="HYD" />
                       <ns1:OperatingAirline Code="AI" />
                       <ns1:BookingClassAvail FareType="RP" ResBookDesigCode="E" ResBookDesigQuantity="5" Status="5" WebFareName="EAP30" />
                       <ns1:Equipment AirEquipType="319" />
                       <ns1:MarketingAirline Code="AI" MatrixCode="AI" Name="Air India" YTAirlineCode="AI" />
                       <ns1:ValidatingCarrier Code="AI" />
                     </ns1:FlightSegment>
                     <ns1:FormData>
                       <ns1:FBC Destination="HYD" FlightNumber="517" LineNumber="Y" Origin="BLR" SeatToSell="5" WebFareName="EAP30" />
                       <ns1:FareDifference>
                         <ns1:TotalFare ADT="1" BaseFare="670-ADT 670" CHD="0" Cabin="Economy" HostName="railserver" INF="0" Rbd="RP - E -" Tax="TTL-2355">3032</ns1:TotalFare>
                       </ns1:FareDifference>
                       <ns1:TicketingInfo DeliveryMethod="Courier" TicketTimeLimit="2013-03-03 18:43:00" TicketType="Physical" />
                       <ns1:AgentMarkup>
                         <ns1:Airlines>
                           <ns1:Airline>
                             <ns1:Code>6E</ns1:Code>
                             <ns1:GDS>0</ns1:GDS>
                             <ns1:WholeSalerFees>0.0000</ns1:WholeSalerFees>
                             <ns1:WholeSalerFeesType>F</ns1:WholeSalerFeesType>
                             <ns1:CommissionType>C</ns1:CommissionType>
                             <ns1:ApplyOn>BF</ns1:ApplyOn>
                             <ns1:Amount>0.0000</ns1:Amount>
                             <ns1:Type>P</ns1:Type>
                             <ns1:DiscountPLB>0.0000</ns1:DiscountPLB>
                             <ns1:DiscountPLBType>F</ns1:DiscountPLBType>
                             <ns1:DiscountPLBOn />
                             <ns1:Surcharge>2700.0000</ns1:Surcharge>
                           </ns1:Airline>
                           <ns1:Airline>
                             <ns1:Code>9H</ns1:Code>
                             <ns1:GDS>0</ns1:GDS>
                             <ns1:WholeSalerFees>0.0000</ns1:WholeSalerFees>
                             <ns1:WholeSalerFeesType>F</ns1:WholeSalerFeesType>
                             <ns1:CommissionType>M</ns1:CommissionType>
                             <ns1:ApplyOn>BF</ns1:ApplyOn>
                             <ns1:Amount>6.0000</ns1:Amount>
                             <ns1:Type>P</ns1:Type>
                             <ns1:DiscountPLB>0.0000</ns1:DiscountPLB>
                             <ns1:DiscountPLBType>F</ns1:DiscountPLBType>
                             <ns1:DiscountPLBOn />
                             <ns1:Surcharge>0.0000</ns1:Surcharge>
                           </ns1:Airline>
                           <ns1:Airline>
                             <ns1:Code>9W</ns1:Code>
                             <ns1:GDS>1</ns1:GDS>
                             <ns1:WholeSalerFees>0.0000</ns1:WholeSalerFees>
                             <ns1:WholeSalerFeesType>F</ns1:WholeSalerFeesType>
                             <ns1:CommissionType>C</ns1:CommissionType>
                             <ns1:ApplyOn>BF</ns1:ApplyOn>
                             <ns1:Amount>0.0000</ns1:Amount>
                             <ns1:Type>P</ns1:Type>
                             <ns1:DiscountPLB>0.0000</ns1:DiscountPLB>
                             <ns1:DiscountPLBType>F</ns1:DiscountPLBType>
                             <ns1:DiscountPLBOn />
                             <ns1:Surcharge>1100.0000</ns1:Surcharge>
                           </ns1:Airline>
                           <ns1:Airline>
                             <ns1:Code>AI</ns1:Code>
                             <ns1:GDS>1</ns1:GDS>
                             <ns1:WholeSalerFees>0.0000</ns1:WholeSalerFees>
                             <ns1:WholeSalerFeesType>F</ns1:WholeSalerFeesType>
                             <ns1:CommissionType>C</ns1:CommissionType>
                             <ns1:ApplyOn>BF</ns1:ApplyOn>
                             <ns1:Amount>0.0000</ns1:Amount>
                             <ns1:Type>P</ns1:Type>
                             <ns1:DiscountPLB>0.0000</ns1:DiscountPLB>
                             <ns1:DiscountPLBType>F</ns1:DiscountPLBType>
                             <ns1:DiscountPLBOn />
                             <ns1:Surcharge>1100.0000</ns1:Surcharge>
                           </ns1:Airline>
                           <ns1:Airline>
                             <ns1:Code>DN</ns1:Code>
                             <ns1:GDS>0</ns1:GDS>
                             <ns1:WholeSalerFees>0.0000</ns1:WholeSalerFees>
                             <ns1:WholeSalerFeesType>F</ns1:WholeSalerFeesType>
                             <ns1:CommissionType>M</ns1:CommissionType>
                             <ns1:ApplyOn>BF</ns1:ApplyOn>
                             <ns1:Amount>6.0000</ns1:Amount>
                             <ns1:Type>P</ns1:Type>
                             <ns1:DiscountPLB>0.0000</ns1:DiscountPLB>
                             <ns1:DiscountPLBType>F</ns1:DiscountPLBType>
                             <ns1:DiscountPLBOn />
                             <ns1:Surcharge>3250.0000</ns1:Surcharge>
                           </ns1:Airline>
                           <ns1:Airline>
                             <ns1:Code>G8</ns1:Code>
                             <ns1:GDS>0</ns1:GDS>
                             <ns1:WholeSalerFees>0.0000</ns1:WholeSalerFees>
                             <ns1:WholeSalerFeesType>F</ns1:WholeSalerFeesType>
                             <ns1:CommissionType>C</ns1:CommissionType>
                             <ns1:ApplyOn>BF</ns1:ApplyOn>
                             <ns1:Amount>0.0000</ns1:Amount>
                             <ns1:Type>P</ns1:Type>
                             <ns1:DiscountPLB>0.0000</ns1:DiscountPLB>
                             <ns1:DiscountPLBType>F</ns1:DiscountPLBType>
                             <ns1:DiscountPLBOn />
                             <ns1:Surcharge>2700.0000</ns1:Surcharge>
                           </ns1:Airline>
                           <ns1:Airline>
                             <ns1:Code>I7</ns1:Code>
                             <ns1:GDS>0</ns1:GDS>
                             <ns1:WholeSalerFees>0.0000</ns1:WholeSalerFees>
                             <ns1:WholeSalerFeesType>F</ns1:WholeSalerFeesType>
                             <ns1:CommissionType>M</ns1:CommissionType>
                             <ns1:ApplyOn>BF</ns1:ApplyOn>
                             <ns1:Amount>6.0000</ns1:Amount>
                             <ns1:Type>P</ns1:Type>
                             <ns1:DiscountPLB>0.0000</ns1:DiscountPLB>
                             <ns1:DiscountPLBType>F</ns1:DiscountPLBType>
                             <ns1:DiscountPLBOn />
                             <ns1:Surcharge>0.0000</ns1:Surcharge>
                           </ns1:Airline>
                           <ns1:Airline>
                             <ns1:Code>IC</ns1:Code>
                             <ns1:GDS>1</ns1:GDS>
                             <ns1:WholeSalerFees>0.0000</ns1:WholeSalerFees>
                             <ns1:WholeSalerFeesType>F</ns1:WholeSalerFeesType>
                             <ns1:CommissionType>C</ns1:CommissionType>
                             <ns1:ApplyOn>BF</ns1:ApplyOn>
                             <ns1:Amount>0.0000</ns1:Amount>
                             <ns1:Type>P</ns1:Type>
                             <ns1:DiscountPLB>0.0000</ns1:DiscountPLB>
                             <ns1:DiscountPLBType>F</ns1:DiscountPLBType>
                             <ns1:DiscountPLBOn />
                             <ns1:Surcharge>1100.0000</ns1:Surcharge>
                           </ns1:Airline>
                           <ns1:Airline>
                             <ns1:Code>IT</ns1:Code>
                             <ns1:GDS>1</ns1:GDS>
                             <ns1:WholeSalerFees>0.0000</ns1:WholeSalerFees>
                             <ns1:WholeSalerFeesType>F</ns1:WholeSalerFeesType>
                             <ns1:CommissionType>C</ns1:CommissionType>
                             <ns1:ApplyOn>BF</ns1:ApplyOn>
                             <ns1:Amount>0.0000</ns1:Amount>
                             <ns1:Type>P</ns1:Type>
                             <ns1:DiscountPLB>0.0000</ns1:DiscountPLB>
                             <ns1:DiscountPLBType>F</ns1:DiscountPLBType>
                             <ns1:DiscountPLBOn />
                             <ns1:Surcharge>1100.0000</ns1:Surcharge>
                           </ns1:Airline>
                           <ns1:Airline>
                             <ns1:Code>S2</ns1:Code>
                             <ns1:GDS>1</ns1:GDS>
                             <ns1:WholeSalerFees>0.0000</ns1:WholeSalerFees>
                             <ns1:WholeSalerFeesType>F</ns1:WholeSalerFeesType>
                             <ns1:CommissionType>C</ns1:CommissionType>
                             <ns1:ApplyOn>BF</ns1:ApplyOn>
                             <ns1:Amount>0.0000</ns1:Amount>
                             <ns1:Type>P</ns1:Type>
                             <ns1:DiscountPLB>0.0000</ns1:DiscountPLB>
                             <ns1:DiscountPLBType>F</ns1:DiscountPLBType>
                             <ns1:DiscountPLBOn />
                             <ns1:Surcharge>1100.0000</ns1:Surcharge>
                           </ns1:Airline>
                           <ns1:Airline>
                             <ns1:Code>SG</ns1:Code>
                             <ns1:GDS>0</ns1:GDS>
                             <ns1:WholeSalerFees>0.0000</ns1:WholeSalerFees>
                             <ns1:WholeSalerFeesType>F</ns1:WholeSalerFeesType>
                             <ns1:CommissionType>C</ns1:CommissionType>
                             <ns1:ApplyOn>BF</ns1:ApplyOn>
                             <ns1:Amount>0.0000</ns1:Amount>
                             <ns1:Type>P</ns1:Type>
                             <ns1:DiscountPLB>0.0000</ns1:DiscountPLB>
                             <ns1:DiscountPLBType>F</ns1:DiscountPLBType>
                             <ns1:DiscountPLBOn />
                             <ns1:Surcharge>2000.0000</ns1:Surcharge>
                           </ns1:Airline>
                           <ns1:Others>
                             <ns1:Code />
                             <ns1:GDS>1</ns1:GDS>
                             <ns1:WholeSalerFees>0</ns1:WholeSalerFees>
                             <ns1:CommissionType>C</ns1:CommissionType>
                             <ns1:ApplyOn>B</ns1:ApplyOn>
                             <ns1:Amount>0.0000</ns1:Amount>
                           </ns1:Others>
                         </ns1:Airlines>
                       </ns1:AgentMarkup>
                     </ns1:FormData>
                     <ns1:FormData />
                   </ns1:OriginDestinationOption>
                 </ns1:OriginDestinationOptions>
               </ns1:AirItinerary>
               <ns1:AirItineraryPricingInfo UniqueIdentifier="1.0">
                 <ns1:ItinTotalFare NegotiatedFare="No">
                   <ns1:BaseFare Amount="670" CurrencyCode="INR" />
                   <ns1:Taxes>
                     <ns1:Tax Amount="2355" CurrencyCode="INR" TaxCode="TTL" />
                   </ns1:Taxes>
                   <ns1:TotalFare Amount="3032" CurrencyCode="INR" />
                   <ns1:Fees>
                     <ns1:Fee Amount="0" />
                     <ns1:Fee Amount="0" FeeCode="YatraLCCSurcharge" />
                   </ns1:Fees>
                   <ns1:ServiceTax Amount="7" Currency="INR" Description="Service Tax" ServiceTaxCode="ST" ServiceTaxRate="0.01" />
                   <ns1:Markups>
                     <ns1:Markup Amount="0" CurrencyCode="INR" Description="0.0 wholesalerfees for client 1152" MarkupCode="DisplayMarkup" MarkupType="W" Type="C" />
                     <ns1:Markup Amount="0" CurrencyCode="INR" Description="0.0% on base fare for client - 1152" MarkupCode="DisplayMarkup" MarkupType="M" Type="C" />
                     <ns1:Markup Amount="0" CurrencyCode="INR" Description="0.0% on fuel surcharge 0 -for client - 1152" MarkupCode="DisplayMarkup" MarkupType="M" Type="C" />
                     <ns1:Markup Amount="0" CurrencyCode="INR" Description="0.0 on base fare for client - 1152" MarkupCode="DisplayMarkup" MarkupType="M" Type="P" />
                   </ns1:Markups>
                 </ns1:ItinTotalFare>
                 <ns1:PTC_FareBreakdowns>
                   <ns1:PTC_FareBreakdown>
                     <ns1:PassengerTypeQuantity Code="ADT" Quantity="1.0" />
                     <ns1:FareBasisCodes>
                       <ns1:FareBasisCode FareType="" SegmentRPH="">EAP30</ns1:FareBasisCode>
                     </ns1:FareBasisCodes>
                     <ns1:PassengerFare>
                       <ns1:BaseFare Amount="670" CurrencyCode="INR" />
                       <ns1:Taxes>
                         <ns1:Tax Amount="2355" CurrencyCode="INR" TaxCode="TTL" />
                       </ns1:Taxes>
                       <ns1:TotalFare Amount="3032" CurrencyCode="INR" />
                       <ns1:ServiceTax Amount="7" Currency="INR" Description="Service Tax" ServiceTaxCode="ST" ServiceTaxRate="0.01" />
                       <ns1:Markups>
                         <ns1:Markup Amount="0.0000" CurrencyCode="INR" Description="0.0 wholesalerfees for client 1152" MarkupCode="DisplayMarkup" MarkupType="W" Type="C" />
                         <ns1:Markup Amount="0" CurrencyCode="INR" Description="0.0 % on base fare for client - 1152" MarkupCode="DisplayMarkup" MarkupType="M" Type="C" />
                         <ns1:Markup Amount="0" Description="0.0% on fule surcharge 0.0for client1152" MarkupCode="DisplayMarkup" MarkupType="M" Type="C" />
                         <ns1:Markup Amount="0" CurrencyCode="INR" Description="0.0 on base fare for client1152" MarkupCode="DisplayMarkup" MarkupType="M" Type="P" />
                       </ns1:Markups>
                     </ns1:PassengerFare>
                   </ns1:PTC_FareBreakdown>
                 </ns1:PTC_FareBreakdowns>
                 <ns1:FareInfos>
                   <ns1:FareInfo>
                     <ns1:FareReference>EAP30</ns1:FareReference>
                     <ns1:FilingAirline Code="ZZ" />
                     <ns1:DepartureAirport LocationCode="BLR" />
                     <ns1:ArrivalAirport LocationCode="HYD" />
                   </ns1:FareInfo>
                 </ns1:FareInfos>
               </ns1:AirItineraryPricingInfo>
               <ns1:TicketingInfo DeliveryMethod="Courier" TicketTimeLimit="2013-03-03 18:43:00" TicketType="Physical" />
               <ns1:Notes>PENALTY APPLIES</ns1:Notes>
               <ns1:Notes>LAST TKT DTE21OCT12 - SEE ADV PURCHASE</ns1:Notes>
             </ns1:PricedItinerary>
                     .
                     .
                     .
                     .
                     .
                     .
               </ns1:PricedItineraries >
         </ns1:OTA_AirLowFareSearchRS >
                           </soapenv:Body >
</soapenv:Envelope >

和我的 xslt 样式表如下:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.opentravel.org/OTA/2003/05"
                xmlns:ns1="http://www.opentravel.org/OTA/2003/05"
                xmlns:soapenv="http://www.opentravel.org/OTA/2003/05"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>


  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="ns1:OTA_AirLowFareSearchRS">
    <table cellpadding="10px">
      <tr>
        <th>
          Airline
        </th>
        <th>
          Departure
        </th>
        <th>

          Arrival
        </th>
        <th>
          Duration
        </th>
        <th>

          Fare Type
        </th>
        <th>
          Per Adult Fare
        </th>

      </tr> 

      <xsl:for-each  select ="ns1:PricedItineraries">

        <tr>
          <td>
            <xsl:value-of  select="./ns1:PricedItinerary/ns1:AirItinerary/ns1:OriginDestinationOptions/ns1:OriginDestinationOption/ns1:FlightSegment/ns1:MarketingAirline/@Name"  />

          </td>
          <td>
            <xsl:value-of  select="substring-after(./ns1:PricedItinerary/ns1:AirItinerary/ns1:OriginDestinationOptions/ns1:OriginDestinationOption/ns1:FlightSegment/@DepartureDateTime,'')" />  
          </td>
          <td>
            <xsl:value-of  select="substring-after(./ns1:PricedItinerary/ns1:AirItinerary/ns1:OriginDestinationOptions/ns1:OriginDestinationOption/ns1:FlightSegment/@ArrivalDateTime,'')" />
          </td>
          <td>
            <xsl:value-of  select=" ./ns1:PricedItinerary/ns1:AirItinerary/ns1:OriginDestinationOptions/ns1:OriginDestinationOption/ns1:FlightSegment/@Duration" />
          </td>
          <td>
             <xsl:choose>
              <xsl:when test="./@Refundable='true'">
                <xsl:text>Refundable</xsl:text>
              </xsl:when>
              <xsl:otherwise>
                <xsl:text>Non-Refundable</xsl:text>
              </xsl:otherwise>
            </xsl:choose>

          </td>
          <td>

            <xsl:value-of  select=" ./ns1:PricedItinerary/ns1:AirItineraryPricingInfo/ns1:PTC_FareBreakdowns/ns1:PTC_FareBreakdown/ns1:PassengerFare/ns1:TotalFare/@Amount" />


          </td>

        </tr>
      <tr>
        <td>
   <xsl:value-of  select="./ns1:PricedItinerary/ns1:AirItinerary/ns1:OriginDestinationOptions/ns1:OriginDestinationOption/ns1:FlightSegment/ns1:MarketingAirline/@YTAirlineCode"  />

        -  <xsl:value-of  select="./ns1:PricedItinerary/ns1:AirItinerary/ns1:OriginDestinationOptions/ns1:OriginDestinationOption/ns1:FormData/ns1:FBC/@FlightNumber"  />


        </td>

        <td>
          <xsl:value-of  select="./ns1:PricedItinerary/ns1:AirItinerary/ns1:OriginDestinationOptions/ns1:OriginDestinationOption/ns1:FlightSegment/ns1:DepartureAirport/@CityName"  />
        </td>
        <td>
          <xsl:value-of  select="./ns1:PricedItinerary/ns1:AirItinerary/ns1:OriginDestinationOptions/ns1:OriginDestinationOption/ns1:FlightSegment/ns1:ArrivalAirport/@CityName"  />
        </td>
        <td></td>
        <td></td> 
      </tr>

      </xsl:for-each>
    </table>
  </xsl:template>
  <xsl:template match="ns1:MarketingAirline">
    </xsl:template >

  <xsl:template match="/">
    <html>
      <body>
        <xsl:apply-templates/>
      </body>
    </html>
  </xsl:template> 


</xsl:stylesheet>
4

1 回答 1

1

这段代码

     <xsl:for-each  select ="ns1:PricedItineraries">
       <!-- Processing intentionally skipped -->
     <xsl:for-each/>

选择所有要处理的节点

提供的元素中只有一个 ns1:PricedItineraries元素——这就是“循环”只执行一次的原因。

解决方案

使用

      <xsl:for-each  select ="ns1:PricedItineraries/ns1:PricedItinerary">

./ns1:PricedItinerary/并在此指令中从任何 XPath 表达式中删除前导

于 2013-03-03T21:57:56.050 回答