homepage Welcome to WebmasterWorld Guest from 54.166.228.100
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
Help with creating XSLT
schenz




msg:701399
 6:26 pm on Aug 30, 2004 (gmt 0)

I have this XML:
<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MessageType>OrderReport</MessageType>
<Message>
<MessageID>1</MessageID>
<OrderReport>
<OrderID>058-4466335-2285957</OrderID>
<SessionID>102-1725329-2267355</SessionID>
<OrderDate>2004-08-30T08:04:50-07:00</OrderDate>
<OrderPostedDate>2004-08-30T08:04:55-07:00</OrderPostedDate>
<BillingData>
<BuyerEmailAddress>lynkendrick@yahoo.com</BuyerEmailAddress>
<BuyerName>Lyn Kendrick</BuyerName>
<BuyerPhoneNumber>505-988-7113</BuyerPhoneNumber>
</BillingData>
<FulfillmentData>
<FulfillmentMethod>Ship</FulfillmentMethod>
<FulfillmentServiceLevel>Standard</FulfillmentServiceLevel>
<Address>
<Name>Zachary Kendrick</Name>
<AddressFieldOne>3682 W. Atwater</AddressFieldOne>
<City>Fresno</City>
<StateOrRegion>CA</StateOrRegion>
<PostalCode>93711</PostalCode>
<CountryCode>US</CountryCode>
<PhoneNumber>559-432-6371</PhoneNumber>
</Address>
</FulfillmentData>
<Item>
<OrderItemCode>54569883065558</OrderItemCode>
<SKU>11320221A</SKU>
<Title>Prince Triple Threat Scream OS Grip Size: 1/8 Tennis Racquet</Title>
<Quantity>1</Quantity>
<ProductTaxCode>A_GEN_NOTAX</ProductTaxCode>
<ItemPrice>
<Component>
<Type>Principal</Type>
<Amount currency="USD">89.95</Amount>
</Component>
<Component>
<Type>Shipping</Type>
<Amount currency="USD">1.74</Amount>
</Component>
<Component>
<Type>Tax</Type>
<Amount currency="USD">0.00</Amount>
</Component>
<Component>
<Type>ShippingTax</Type>
<Amount currency="USD">0.00</Amount>
</Component>
<Component>
<Type>GiftWrap</Type>
<Amount currency="USD">0.00</Amount>
</Component>
<Component>
<Type>GiftWrapTax</Type>
<Amount currency="USD">0.00</Amount>
</Component>
</ItemPrice>
<ItemFees>
<Fee>
<Type>Commission</Type>
<Amount currency="USD">-13.49</Amount>
</Fee>
</ItemFees>
<Promotion>
<PromotionClaimCode>_SITE_WIDE_</PromotionClaimCode>
<MerchantPromotionID>AugFreeShipping</MerchantPromotionID>
<Component>
<Type>Shipping</Type>
<Amount currency="USD">-1.74</Amount>
</Component>
</Promotion>
<GiftMessageText>Zac, Hope this racquet fits! Enjoy! Much love, Lyn &#38; Curt</GiftMessageText>
</Item>
<Item>
<OrderItemCode>18815179612750</OrderItemCode>
<SKU>4132015</SKU>
<Title>Prince Force Backpack Tennis Bag - 6P904-010</Title>
<Quantity>1</Quantity>
<ProductTaxCode>A_GEN_NOTAX</ProductTaxCode>
<ItemPrice>
<Component>
<Type>Principal</Type>
<Amount currency="USD">19.95</Amount>
</Component>
<Component>
<Type>Shipping</Type>
<Amount currency="USD">1.74</Amount>
</Component>
<Component>
<Type>Tax</Type>
<Amount currency="USD">0.00</Amount>
</Component>
<Component>
<Type>ShippingTax</Type>
<Amount currency="USD">0.00</Amount>
</Component>
</ItemPrice>
<ItemFees>
<Fee>
<Type>Commission</Type>
<Amount currency="USD">-2.99</Amount>
</Fee>
</ItemFees>
<Promotion>
<PromotionClaimCode>_SITE_WIDE_</PromotionClaimCode>
<MerchantPromotionID>AugFreeShipping</MerchantPromotionID>
<Component>
<Type>Shipping</Type>
<Amount currency="USD">-1.74</Amount>
</Component>
</Promotion>
</Item>
<Item>
<OrderItemCode>53858858575846</OrderItemCode>
<SKU>5134003</SKU>
<Title>Penn Pro Regular Duty Can Tennis Ball</Title>
<Quantity>2</Quantity>
<ProductTaxCode>A_GEN_NOTAX</ProductTaxCode>
<ItemPrice>
<Component>
<Type>Principal</Type>
<Amount currency="USD">5.00</Amount>
</Component>
<Component>
<Type>Shipping</Type>
<Amount currency="USD">3.47</Amount>
</Component>
<Component>
<Type>Tax</Type>
<Amount currency="USD">0.00</Amount>
</Component>
<Component>
<Type>ShippingTax</Type>
<Amount currency="USD">0.00</Amount>
</Component>
</ItemPrice>
<ItemFees>
<Fee>
<Type>Commission</Type>
<Amount currency="USD">-0.76</Amount>
</Fee>
</ItemFees>
<Promotion>
<PromotionClaimCode>_SITE_WIDE_</PromotionClaimCode>
<MerchantPromotionID>AugFreeShipping</MerchantPromotionID>
<Component>
<Type>Shipping</Type>
<Amount currency="USD">-3.47</Amount>
</Component>
</Promotion>
</Item>
</OrderReport>
</Message>
<Message>
<MessageID>2</MessageID>
<OrderReport>
<OrderID>058-7463504-7400320</OrderID>
<SessionID>102-8259823-6018539</SessionID>
<OrderDate>2004-08-30T08:04:31-07:00</OrderDate>
<OrderPostedDate>2004-08-30T08:04:36-07:00</OrderPostedDate>
<BillingData>
<BuyerEmailAddress>freakfunky@aol.com</BuyerEmailAddress>
<BuyerName>Bill Coate</BuyerName>
<BuyerPhoneNumber>212.965.1870</BuyerPhoneNumber>
</BillingData>
<FulfillmentData>
<FulfillmentMethod>Ship</FulfillmentMethod>
<FulfillmentServiceLevel>Standard</FulfillmentServiceLevel>
<Address>
<Name>Bill Coate</Name>
<AddressFieldOne>10 West St. # 24-D</AddressFieldOne>
<City>New York</City>
<StateOrRegion>NY</StateOrRegion>
<PostalCode>10004</PostalCode>
<CountryCode>US</CountryCode>
<PhoneNumber>212.965.1870</PhoneNumber>
</Address>
</FulfillmentData>
<Item>
<OrderItemCode>32316429306518</OrderItemCode>
<SKU>11510075B</SKU>
<Title>Wilson nCode nSixOne Tour 90 Tennis Racquet - T7561P Grip Size: 4 1/4</Title>
<Quantity>1</Quantity>
<ProductTaxCode>A_GEN_NOTAX</ProductTaxCode>
<ItemPrice>
<Component>
<Type>Principal</Type>
<Amount currency="USD">179.95</Amount>
</Component>
<Component>
<Type>Shipping</Type>
<Amount currency="USD">6.95</Amount>
</Component>
<Component>
<Type>Tax</Type>
<Amount currency="USD">0.00</Amount>
</Component>
<Component>
<Type>ShippingTax</Type>
<Amount currency="USD">0.00</Amount>
</Component>
</ItemPrice>
<ItemFees>
<Fee>
<Type>Commission</Type>
<Amount currency="USD">-26.99</Amount>
</Fee>
</ItemFees>
<Promotion>
<PromotionClaimCode>_SITE_WIDE_</PromotionClaimCode>
<MerchantPromotionID>AugFreeShipping</MerchantPromotionID>
<Component>
<Type>Shipping</Type>
<Amount currency="USD">-6.95</Amount>
</Component>
</Promotion>
</Item>
</OrderReport>
</Message>
</Envelope>

I want to add the Shipping Totals for each of the different orders (Message) into one total that I store in the Orders Table of my DB. I guess I need to use recursion, but nothing I have read on this is making any sense to me. It also does not help that they are using a <Component> tag then a <Type> to identify what each pricing item is. How do I return just the Shipping value, then add them up for a grand total?

(Better formated example available on request)

 

schenz




msg:701400
 6:38 pm on Aug 30, 2004 (gmt 0)

Also, while I'm at it. Is there a way to setup a sort of auto-increment number? I have used (xsl:value-of select="position()" />, but this is reset to 1 when the master node changes, and I would instead like to continue with the numbers in order.

brucec




msg:701401
 6:01 pm on Sep 2, 2004 (gmt 0)

You can accomplish it with Javascript in your XSLT or better yet, instead of using JS, you could try using a server side scripting language like ASP or PHP to increment the numbers and create the XML on the fly. Then use your xsl:value-of select to grab the value.

schenz




msg:701402
 3:58 pm on Sep 3, 2004 (gmt 0)

I do not care so much about the auto-increment stuff, I'll work around it.....

Here is the solution for the Adding of the Shipping Totals:
ok, this seems to be the solution:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<x#*$!put method="html" indent="yes"/>
<xsl:include href="Style1.xsl"/>

<xsl:template match="/">
<!-- Call the cosmetic formatting template -->
<xsl:call-template name="Style1"/>
<html><body>
<xsl:apply-templates/>
</body></html>
</xsl:template>

<xsl:template match="Envelope/Message">
<h1>Order Number: <xsl:value-of select="OrderReport/OrderID" /></h1>
Total Shipping: <xsl:value-of select="sum(OrderReport/Item/*/Component[Type='Shipping']/Amount)" />
</xsl:template>
Edit/Delete Message

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved