xml - xslt for-each repeating same for all the nodes -
source xml: same node repeated in for-each used in xslt. need loop through line items. if have 3 line items, for-each repeated 3 times same first line item..
<?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 order working fine. having problem 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 for-each nodes. issue. in out put see first line item tw2p84400za repeated 3 times. **>tw2p84400za< >tw2p84400za< >tw2p84400za<** instead need see line items in output **>tw2p84400za< >tw2p919009j< >tw7c06900gz<**
thanks
the problem, in nutshell, this:
when do:
<xsl:for-each select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem">
you put in context of product-lineitem
. context, need specify relative path product id:
<xsl:value-of select="imp1:product-id"/>
in order select current line-item's product-id
.
instead, do:
<xsl:value-of select="/imp1:orders/imp1:order/imp1:product-lineitems/imp1:product-lineitem/imp1:product-id"/>
which selects product-id
nodes in entire document, starting root, , - in xslt 1.0 - returns value of first one.
Comments
Post a Comment