XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 30th, 2004, 11:32 PM
schenz schenz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 22 schenz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 57 m 28 sec
Reputation Power: 0
Help with creating XSLT

I have this XML:
<AmazonEnvelope xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Message>
<MessageID>1</MessageID>
-
<OrderReport>
<AmazonOrderID>058-0986845-5785165</AmazonOrderID>
<AmazonSessionID>103-5085382-1579837</AmazonSessionID>
<OrderDate>2004-08-30T19:34:43-07:00</OrderDate>
<OrderPostedDate>2004-08-30T19:34:52-07:00</OrderPostedDate>
-
<BillingData>
<BuyerEmailAddress>dadolf3@comcast.net</BuyerEmailAddress>
<BuyerName>Douglas Adolf</BuyerName>
<BuyerPhoneNumber>(505)298-2270</BuyerPhoneNumber>
</BillingData>
-
<FulfillmentData>
<FulfillmentMethod>Ship</FulfillmentMethod>
<FulfillmentServiceLevel>Standard</FulfillmentServiceLevel>
-
<Address>
<Name>Douglas Adolf</Name>
<AddressFieldOne>11105 Double Eagle NE</AddressFieldOne>
<City>Albuquerque</City>
<StateOrRegion>NM</StateOrRegion>
<PostalCode>87111</PostalCode>
<CountryCode>US</CountryCode>
<PhoneNumber>(505)298-2270</PhoneNumber>
</Address>
</FulfillmentData>
-
<Item>
<AmazonOrderItemCode>13487926545166</AmazonOrderItemCode>
<SKU>11320221E</SKU>
-
<Title>
Prince Triple Threat Scream OS Grip Size: 5/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.39</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">-13.49</Amount>
</Fee>
</ItemFees>
-
<Promotion>
<PromotionClaimCode>_SITE_WIDE_</PromotionClaimCode>
<MerchantPromotionID>AugFreeShipping</MerchantPromotionID>
-
<Component>
<Type>Shipping</Type>
<Amount currency="USD">-1.39</Amount>
</Component>
</Promotion>
</Item>
-
<Item>
<AmazonOrderItemCode>51817123432614</AmazonOrderItemCode>
<SKU>3151016/DarkGray</SKU>
<Title>Wilson H2Overgrip (3) Color: Dark Gray</Title>
<Quantity>2</Quantity>
<ProductTaxCode>A_GEN_NOTAX</ProductTaxCode>
-
<ItemPrice>
-
<Component>
<Type>Principal</Type>
<Amount currency="USD">5.98</Amount>
</Component>
-
<Component>
<Type>Shipping</Type>
<Amount currency="USD">2.78</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.90</Amount>
</Fee>
</ItemFees>
-
<Promotion>
<PromotionClaimCode>_SITE_WIDE_</PromotionClaimCode>
<MerchantPromotionID>AugFreeShipping</MerchantPromotionID>
-
<Component>
<Type>Shipping</Type>
<Amount currency="USD">-2.78</Amount>
</Component>
</Promotion>
</Item>
-
<Item>
<AmazonOrderItemCode>16079481441886</AmazonOrderItemCode>
<SKU>3132018/Black</SKU>
<Title>Duratac Color: Black Replacement Grip</Title>
<Quantity>2</Quantity>
<ProductTaxCode>A_GEN_NOTAX</ProductTaxCode>
-
<ItemPrice>
-
<Component>
<Type>Principal</Type>
<Amount currency="USD">7.98</Amount>
</Component>
-
<Component>
<Type>Shipping</Type>
<Amount currency="USD">2.78</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">-1.20</Amount>
</Fee>
</ItemFees>
-
<Promotion>
<PromotionClaimCode>_SITE_WIDE_</PromotionClaimCode>
<MerchantPromotionID>AugFreeShipping</MerchantPromotionID>
-
<Component>
<Type>Shipping</Type>
<Amount currency="USD">-2.78</Amount>
</Component>
</Promotion>
</Item>
</OrderReport>
</Message>
-
<Message>
<MessageID>2</MessageID>
-
<OrderReport>
<AmazonOrderID>058-3665855-3201150</AmazonOrderID>
<AmazonSessionID>104-4395839-5827108</AmazonSessionID>
<OrderDate>2004-08-30T16:59:10-07:00</OrderDate>
<OrderPostedDate>2004-08-30T19:38:32-07:00</OrderPostedDate>
-
<BillingData>
<BuyerEmailAddress>dancassey@cox.net</BuyerEmailAddress>
<BuyerName>Daniel A. Cassey</BuyerName>
<BuyerPhoneNumber>623-374-7116</BuyerPhoneNumber>
</BillingData>
-
<FulfillmentData>
<FulfillmentMethod>Ship</FulfillmentMethod>
<FulfillmentServiceLevel>Standard</FulfillmentServiceLevel>
-
<Address>
<Name>Daniel A. Cassey</Name>
<AddressFieldOne>41004 N. Congressional Dr.</AddressFieldOne>
<City>Anthem</City>
<StateOrRegion>AZ</StateOrRegion>
<PostalCode>85086</PostalCode>
<CountryCode>US</CountryCode>
<PhoneNumber>623-374-7116</PhoneNumber>
</Address>
</FulfillmentData>
-
<Item>
<AmazonOrderItemCode>62029783008806</AmazonOrderItemCode>
<SKU>215101719B</SKU>
-
<Title>
Wilson Fli-By Tennis Shoes Mens Black/Off White/Black - S1360 Size: 9.5
</Title>
<Quantity>1</Quantity>
<ProductTaxCode>A_GEN_NOTAX</ProductTaxCode>
-
<ItemPrice>
-
<Component>
<Type>Principal</Type>
<Amount currency="USD">44.95</Amount>
</Component>
-
<Component>
<Type>Shipping</Type>
<Amount currency="USD">3.48</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">-7.26</Amount>
</Fee>
</ItemFees>
</Item>
-
<Item>
<AmazonOrderItemCode>30539998874590</AmazonOrderItemCode>
<SKU>215101729B</SKU>
-
<Title>
Wilson Fli-By Tennis Shoes Mens White/ Pewter/Red - S1361 Size: 9.5
</Title>
<Quantity>1</Quantity>
<ProductTaxCode>A_GEN_NOTAX</ProductTaxCode>
-
<ItemPrice>
-
<Component>
<Type>Principal</Type>
<Amount currency="USD">44.95</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">-7.26</Amount>
</Fee>
</ItemFees>
</Item>
</OrderReport>
</Message>
</AmazonEnvelope>

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)

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.

Reply With Quote
  #2  
Old August 31st, 2004, 05:11 AM
IvanE IvanE is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 98 IvanE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 19 m 38 sec
Reputation Power: 5
Yeah it seems recursion is what you need. You have 2 templates, the first one is the recursive one and the second one carries out what you need to do. But the important thing is that the second one has parameters for the information you need to change.

So in the first template, you set your parameter to 0, put in a loop to go through each node you have, calling the second template (passing the parameter) within the loop & getting the total. Set the parameter equal to itself + the total.

If there's a second node, it will loop a second time but this time calling the second template and passing a different parameter value (0 + the total of first loop).

And this will continue for how ever many nodes you need to process.

You'll no doubt have to use your XPath well in order to get the right nodes.

I hope this helps in some way......

Reply With Quote
  #3  
Old September 2nd, 2004, 12:46 PM
schenz schenz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 22 schenz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 57 m 28 sec
Reputation Power: 0
Re: Help with creating XSLT

ok, I'm still having problems here as I'm a newbie with XSLT....

Let us work through this.....

I have this XSLT....

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xslutput 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="AmazonEnvelope/Message">
<h1>Order Number: <xsl:value-of select="OrderReport/AmazonOrderID" /></h1>
<xsl:apply-templates select="OrderReport/Item/ItemPrice" />
</xsl:template>

<xsl:template match="AmazonEnvelope/Message/OrderReport/Item/ItemPrice">
<xsl:variable name="MyTotal">
<xsl:call-template name="TotalShipping">
<xsl:with-param name="componentList" select="//Component/Type" />
<xsl:with-param name="Amount" select="//Component/Amount" />
</xsl:call-template>
</xsl:variable>
Testing Total <xsl:value-of select="$MyTotal" />
</xsl:template>

<xsl:template name="TotalShipping">
<xslaram name="componentList" />
<xslaram name="Amount" />
<xslaram name="Total" select="0" />

<xsl:choose>
<xsl:when test="$componentList">
<!-- Store Components into another variable -->
<xsl:variable name="remainingComponents" select="$componentList[position() != 1]" />
<xsl:variable name="remainingAmounts" select="$Amount[position() != 1]" />
<!-- If Component = Shipping Then Add Amount to Total -->
<xsl:variable name="newTotal">
<xsl:choose>
<xsl:when test="$componentList[1] = 'Shipping'">
<xsl:value-of select="$Total + $Amount" />
</xsl:when>
<xsltherwise>
<xsl:value-of select="$Total" />
</xsltherwise>
</xsl:choose>
</xsl:variable>
<!-- Recursivly call the current template with the new total -->
<xsl:call-template name="TotalShipping">
<xsl:with-param name="Component" select="$remainingComponents" />
<xsl:with-param name="Amount" select="$remainingAmounts" />
<xsl:with-param name="Total" select="$newTotal" />
</xsl:call-template>
This is inside the Component List<xsl:value-of select="$componentList" /><br />
</xsl:when>

<xsltherwise>
<!-- This should be the shipping total -->
<xsl:value-of select="$Total" />
This is inside the Otherwise<xsl:value-of select="$componentList" /><br />
</xsltherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>

But I'm always getting a 0 total. I need to look at the Type in the component and only add the amount if the type is shipping. Here is a small bit of the XML:

<Item>
<AmazonOrderItemCode>44968472139374</AmazonOrderItemCode>
<SKU>31510331/Natural</SKU>
<Title>Wilson Sensation Size: 16G Color: Natural Tennis String</Title>
<Quantity>1</Quantity>
<ProductTaxCode>A_GEN_NOTAX</ProductTaxCode>
<ItemPrice>
<Component>
<Type>Principal</Type>
<Amount currency="USD">7.99</Amount>
</Component>
<Component>
<Type>Shipping</Type>
<Amount currency="USD">2.32</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">-1.20</Amount>
</Fee>
</ItemFees>
<Promotion>
<PromotionClaimCode>_SITE_WIDE_</PromotionClaimCode>
<MerchantPromotionID>AugFreeShipping</MerchantPromotionID>
<Component>
<Type>Shipping</Type>
<Amount currency="USD">-2.32</Amount>
</Component>
</Promotion>
</Item>
<Item>
<AmazonOrderItemCode>47521631197630</AmazonOrderItemCode>
<SKU>2131016B11B</SKU>
<Title>New Balance Ladies CT 820 B Tennis Shoes Size: 10</Title>
<Quantity>1</Quantity>
<ProductTaxCode>A_GEN_NOTAX</ProductTaxCode>
<ItemPrice>
<Component>
<Type>Principal</Type>
<Amount currency="USD">67.95</Amount>
</Component>
<Component>
<Type>Shipping</Type>
<Amount currency="USD">2.31</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">-10.19</Amount>
</Fee>
</ItemFees>
<Promotion>
<PromotionClaimCode>_SITE_WIDE_</PromotionClaimCode>
<MerchantPromotionID>AugFreeShipping</MerchantPromotionID>
<Component>
<Type>Shipping</Type>
<Amount currency="USD">-2.31</Amount>
</Component>
</Promotion>
</Item>
<Item>
<AmazonOrderItemCode>09196731372550</AmazonOrderItemCode>
<SKU>9151013TE</SKU>
<Title>Wilson Total Eclipse Hat - Z1350</Title>
<Quantity>1</Quantity>
<ProductTaxCode>A_GEN_NOTAX</ProductTaxCode>
<ItemPrice>
<Component>
<Type>Principal</Type>
<Amount currency="USD">24.95</Amount>
</Component>
<Component>
<Type>Shipping</Type>
<Amount currency="USD">2.32</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">-3.74</Amount>
</Fee>
</ItemFees>
<Promotion>
<PromotionClaimCode>_SITE_WIDE_</PromotionClaimCode>
<MerchantPromotionID>AugFreeShipping</MerchantPromotionID>
<Component>
<Type>Shipping</Type>
<Amount currency="USD">-2.32</Amount>
</Component>
</Promotion>
</Item>

This has 3 Item nodes that must be looked at, then in the ItemPrice Node there are 4 Component Nodes (I only need the one with a Type = Shipping). So I need to add the 3 Item/ItemPrice/Component/Amount fields where the Type = Shipping.

Once I have that figured out, then I'll need to look at the Promotion node to see if shipping needs to be backed out.....

Once again I apologize if this seems basic to anyone, but I am new to XSLT.

Reply With Quote
  #4  
Old September 3rd, 2004, 11:55 AM
schenz schenz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 22 schenz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 57 m 28 sec
Reputation Power: 0
Help with creating XSLT - Solution

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">
<xslutput 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="AmazonEnvelope/Message">
<h1>Order Number: <xsl:value-of select="OrderReport/AmazonOrderID" /></h1>
Total Shipping: <xsl:value-of select="sum(OrderReport/Item/*/Component[Type='Shipping']/Amount)" />
</xsl:template>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Help with creating XSLT


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT