2016-04-25 23 views
-2

Quell-XML: Der gleiche Knoten wird in der for-jedes in der xslt verwendet wiederholt. Ich muss es durch alle Werbebuchungen durchlaufen. Wenn ich drei Positionen haben, for-each wiederholt wird 3-mal mit dem gleichen Artikel ersten Zeile ..xslt for-each für alle Knoten gleich

 <?xml version="1.0" encoding="UTF-8"?> 
     <orders xmlns="http://www.oracle.com"> 
        <product-lineitems> 
        <product-lineitem> 
         <net-price>100.00</net-price> 
         <tax>6.35</tax> 
         <gross-price>106.35</gross-price> 
         <base-price>100</base-price> 
         <lineitem-text>Originals Modern</lineitem-text> 
         <tax-basis>100.00</tax-basis> 
         <product-id>TW2P84400ZA</product-id> 
         <product-name>The Waterbury</product-name> 
         <quantity unit="">1.0</quantity> 
         <tax-rate>0.0635</tax-rate> 
         <shipment-id>1234</shipment-id> 
        </product-lineitem> 
        <product-lineitem> 
         <net-price>130.00</net-price> 
         <tax>8.26</tax> 
         <gross-price>138.26</gross-price> 
         <base-price>65.00</base-price> 
         <lineitem-text>Weekender Slip-thru</lineitem-text> 
         <tax-basis>130.00</tax-basis> 
         <product-id>TW2P919009J</product-id> 
         <product-name>Weekender Fairfield65</product-name> 
         <quantity unit="">2.0</quantity> 
         <tax-rate>0.0635</tax-rate> 
         <shipment-id>1234</shipment-id> 
         <price-adjustments> 
          <price-adjustment> 
           <net-price>-26.00</net-price> 
           <tax>-1.65</tax> 
           <gross-price>-27.65</gross-price> 
           <base-price>-26.00</base-price> 
           <tax-basis>-26.00</tax-basis> 
           <promotion-id>fathers_day_20</promotion-id> 
           <campaign-id>FATHER'S DAY 20% OFF - 04/01/14 9:22:15 am</campaign-id> 
           <coupon-id>FATHER20</coupon-id> 
          </price-adjustment> 
         </price-adjustments> 
        </product-lineitem> 
        <product-lineitem> 
         <net-price>60.00</net-price> 
         <tax>3.81</tax> 
         <gross-price>63.81</gross-price> 
         <base-price>20.00</base-price> 
         <lineitem-text>Straps - Weekender</lineitem-text> 
         <tax-basis>60.00</tax-basis> 
         <product-id>TW7C06900GZ</product-id> 
         <product-name>Weekender™ Fairfield Red/White/Blue Strap, 20mm</product-name> 
         <quantity unit="">3.0</quantity> 
         <tax-rate>0.0635</tax-rate> 
         <shipment-id>1234</shipment-id> 
         <price-adjustments> 
          <price-adjustment> 
           <net-price>-12.00</net-price> 
           <tax>-0.76</tax> 
           <gross-price>-12.76</gross-price> 
           <base-price>-12.00</base-price> 
           <tax-basis>-12.00</tax-basis> 
           <promotion-id>fathers_day_20</promotion-id> 
           <campaign-id>FATHER'S DAY 20% OFF - 04/01/14 9:22:15 am</campaign-id> 
           <coupon-id>FATHER20</coupon-id> 
          </price-adjustment> 
         </price-adjustments> 
        </product-lineitem> 
       </product-lineitems> 
       <shipping-lineitems> 
        <shipping-lineitem> 
         <net-price>12.95</net-price> 
         <tax>0.82</tax> 
         <gross-price>13.77</gross-price> 
         <base-price>12.95</base-price> 
         <lineitem-text>Shipping</lineitem-text> 
         <tax-basis>12.95</tax-basis> 
         <price-adjustment> 
          <net-price>-7.95</net-price> 
          <tax>-0.50</tax> 
          <gross-price>-8.45</gross-price> 
          <base-price>-7.95</base-price> 
          <tax-basis>-7.95</tax-basis> 
          <lineitem-text>$5 Expedited Shipping</lineitem-text> 
          <promotion-id>fathers_day_shipping</promotion-id> 
          <campaign-id>FATHER'S DAY $5 Shipping - 04/01/14 9:22:15 am</campaign-id> 
          <coupon-id>FATHER20</coupon-id> 
         </price-adjustment> 
         <item-id>EXPEDITED_SHIPPING</item-id> 
         <shipment-id>1234</shipment-id> 
         <tax-rate>.0635</tax-rate> 
        </shipping-lineitem> 
       </shipping-lineitems> 
       <shipments> 
        <shipment> 
         <shipping-method>EXPEDITED-SHIPPING</shipping-method> 
         <shipping-address> 
          <first-name>Satish</first-name> 
          <last-name>Kumar</last-name> 
          <address1>555 Christian Rd</address1> 
          <address2>Middlebury</address2> 
          <city>CT</city> 
          <postal-code>06762</postal-code> 
          <state-code>CT</state-code> 
          <country-code>US</country-code> 
          <phone>2033461234</phone> 
         </shipping-address> 
         <shipment-id></shipment-id> 
        </shipment> 
       </shipments> 
       <totals> 
        <merchandize-total> 
         <net-price>290.00</net-price> 
         <tax>18.42</tax> 
         <gross-price>308.42</gross-price> 
        </merchandize-total> 
        <adjusted-merchandize-total> 
         <net-price>252.00</net-price> 
         <tax>16.00</tax> 
         <gross-price>268.83</gross-price> 
        </adjusted-merchandize-total> 
        <shipping-total> 
         <net-price>12.95</net-price> 
         <tax>0.82</tax> 
         <gross-price>13.77</gross-price> 
        </shipping-total> 
        <adjusted-shipping-total> 
         <net-price>5.00</net-price> 
         <tax>0.32</tax> 
         <gross-price>5.32</gross-price> 
        </adjusted-shipping-total> 
        <order-total> 
         <net-price>257.00</net-price> 
         <tax>16.32</tax> 
         <gross-price>273.32</gross-price> 
        </order-total> 
       </totals> 
       <payments> 
        <payment> 
         <credit-card> 
          <card-type>VISA</card-type> 
          <card-token>AH92FU288BS</card-token> 
          <card-holder>Jon Paul</card-holder> 
          <expiration-month>1</expiration-month> 
          <expiration-year>2017</expiration-year> 
         </credit-card> 
         <amount>185.05</amount> 
         <transaction-id>XYZ123</transaction-id> 
         <processor-id>MYINFO</processor-id> 
         <transaction-type>AUTH</transaction-type> 
         <orderBusinessType>B2C</orderBusinessType> 
        </payment> 
       </payments> 
      </order> 
     </orders> 


    XSLT USED: 

    <template match="/"> 
      <!--HEADERS LEVEL MAPPING FOR THE ORDER IS WORKING FINE. I AM HAVING A PROBLEM WITH THE LINES MAPPING.--> 
     </XxtgEcomOmsHeadersAll> 
     <xxtgEcomOmsLinesAllCollection> 
      <for-each select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem"> 
      <XxtgEcomOmsLinesAll> 

       <tmxFwp> 
       <value-of select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem/imp1:product-id"/> 
       </tmxFwp> 
       <qtyOrdered> 
       <value-of select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem/imp1:quantity"/> 
       </qtyOrdered> 
       <lineDescription> 
       <value-of select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem/imp1:product-name"/> 
       </lineDescription> 
       <lineStatusCode> 
       <value-of select="/imp1:orders/imp1:order/imp1:status/imp1:order-status"/> 
       </lineStatusCode> 
       <omsLinePrice> 
       <value-of select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem/imp1:net-price"/> 
       </omsLinePrice> 
       <omsLineTax> 
       <value-of select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem/imp1:tax"/> 
       </omsLineTax> 
       <omsLineGrossPrice> 
       <value-of select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem/imp1:gross-price"/> 
       </omsLineGrossPrice> 
       <omsLineBasePrice> 
       <value-of select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem/imp1:base-price"/> 
       </omsLineBasePrice> 
       <omsLineItemText> 
       <value-of select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem/imp1:lineitem-text"/> 
       </omsLineItemText> 
       <omsLineTaxBasis> 
       <value-of select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem/imp1:tax-basis"/> 
       </omsLineTaxBasis> 
       <omsLineTaxRate> 
       <value-of select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem/imp1:tax-rate"/> 
       </omsLineTaxRate> 
       <omsLineNetPriceAdj> 
       <value-of select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem/imp1:price-adjustments/imp1:price-adjustment/imp1:net-price"/> 
       </omsLineNetPriceAdj> 
       <omsLineTaxAdj> 
       <value-of select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem/imp1:price-adjustments/imp1:price-adjustment/imp1:tax"/> 
       </omsLineTaxAdj> 
       <omsLineGrossPriceAdj> 
       <value-of select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem/imp1:price-adjustments/imp1:price-adjustment/imp1:gross-price"/> 
       </omsLineGrossPriceAdj> 
       <omsLineBasePriceAdj> 
       <value-of select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem/imp1:price-adjustments/imp1:price-adjustment/imp1:base-price"/> 
       </omsLineBasePriceAdj> 
       <omsLineTaxBasisAdj> 
       <value-of select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem/imp1:price-adjustments/imp1:price-adjustment/imp1:tax-basis"/> 
       </omsLineTaxBasisAdj> 
       <omsLinePromotionId> 
       <value-of select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem/imp1:price-adjustments/imp1:price-adjustment/imp1:promotion-id"/> 
       </omsLinePromotionId> 
       <omsLineCompaignId> 
       <value-of select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem/imp1:price-adjustments/imp1:price-adjustment/imp1:campaign-id"/> 
       </omsLineCompaignId> 
       <omsLineCouponId> 
       <value-of select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem/imp1:price-adjustments/imp1:price-adjustment/imp1:coupon-id"/> 
       </omsLineCouponId> 
       <lineUnitPrice> 
       <value-of select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem/imp1:base-price"/> 
       </lineUnitPrice> 
       <lineUnitCost> 
       <value-of select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem/imp1:base-price"/> 
       </lineUnitCost> 
       </XxtgEcomOmsLinesAll> 
      </for-each> 

    </template> 

Unable to do the for-each for all the nodes. That is the issue. 


In out put i see first line item TW2P84400ZA repeated 3 times. 
**>TW2P84400ZA< 
>TW2P84400ZA< 
>TW2P84400ZA<**  

Instead i need to see all the line items in the output 
**>TW2P84400ZA< 
>TW2P919009J< 
>TW7C06900GZ<** 

Dank

+1

Dies hat das Zeug zu einer guten Frage, aber wenn Sie uns nicht das XSL-Stylesheet und ausreichende tatsächliche vs erwartete Ausgabe zeigen, ist diese Frage unbeantwortbar und wird geschlossen. Bitte besuchen Sie die [Hilfe] und lesen [fragen]. –

+0

Da der Code hier zu lang ist, um ihn einzufügen. Ich habe die genauen XSLT-Funktionen, die ich verwendet habe, und die fertige Eingabe-XML gezeigt. Alles, was ich brauche, ist die Wiederholung der Zeilen im For-Each. Ab jetzt kann ich nur die gleiche erste Zeile wiederholen, die sich für das Nein der Zeilen wiederholt ... – user3866987

+2

Die erste Regel, um um Hilfe zu bitten, ist es, Leuten zu helfen, Ihnen zu helfen. Auf der sehr _least_ zeigen einige der tatsächlichen vs erwartete Ausgabe. Besser noch, erstellen Sie einen einfacheren Testfall, der Ihr Problem zeigt, das klein genug ist, um hier zu posten. Sie könnten das Problem selbst herausfinden. Ich bin seit 7 ½ Jahren auf dieser Seite und habe tausende von Fragen beantwortet. Ich habe insgesamt 21 Fragen gestellt, vor allem, weil ich immer eine Antwort finde, wenn ich eine vereinfachte Version erstellen möchte Hier. –

Antwort

0

Das Problem, auf den Punkt gebracht, ist dies:

Wenn Sie tun:

<xsl:for-each select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem"> 

Sie werden in den Kontext von product-lineitem gesetzt. Aus diesem Zusammenhang müssen Sie nur den relativen Pfad zur Produkt-ID angeben:

<xsl:value-of select="imp1:product-id"/> 

, um das aktuelle Line-Element product-id auszuwählen.

Stattdessen Sie tun:

<xsl:value-of select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem/imp1:product-id"/> 

die alle product-id Knoten in dem gesamten Dokument auswählt, von der Wurzel ausgehend, und - in XSLT 1.0 - den Wert des ersten zurückgibt.

+0

Dies adressiert mein Problem. Danke für die ausführliche Erklärung, obwohl meine Frage nicht nach den Regeln gestaltet wurde. Vielen Dank – user3866987