[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XSL Trnasfromation - Is it possible to do a bottom

Subject: Re: XSL Trnasfromation - Is it possible to do a bottom up transformation?
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Mon, 19 Nov 2007 08:51:21 +0100
Re:  XSL Trnasfromation - Is it possible to do a bottom
Hi Raghu,

See my remarks below,

Cheers,
-- Abel Braaksma

Raghu Narayan Koratagere wrote:

Each line is defined as below: ===================== <orderline> <linenum>1</linenum> <productName>15' Monitor</productName> <netPrice>100</netPrice> <itemTypeCode>1</itemTypeCode> <untiPrice> To be caluclated </unitPrice> <orderline></orderline> <orderline></orderline> <orderline></orderline> <orderline></orderline> <orderline></orderline> </orderline>

I need to calculate a new element called unitPrice based on the below logic:

1. If the itemTypeCode of the current Item is '1' then unitPrice is netPrice

<xsl:template match="unitPrice[../itemTypeCode = '1']">
<xsl:copy><xsl:value-of select="../netPrice" /></xsl:copy>
</xsl:template>
2. If the itemTypeCode of the current Item is '2' then unitPrice is
sum of all the (unitPrice/quantity) of all the child lines

<xsl:template match="unitPrice[../itemTypeCode = '2']">
<xsl:copy><xsl:value-of select="sum(../unitPrice div ../quantity)" /></xsl:copy>
</xsl:template>


3. If the itemTypeCode of the current Item is '3' then unitPrice is
Sum of unitPrice of only the first level child elements

<xsl:template match="unitPrice[../itemTypeCode = '3']">
<xsl:copy><xsl:value-of select="sum(../unitPrice[1] div ../quantity[1])" /></xsl:copy>
</xsl:template>



Unfortunately, it is quite unclear from your (not-well-formed!!) source sample code what you mean by "child element". Please provide a working set of source xml, and show us the XSLT that you currently have with the part that's troubling you. In lieu of this, please make clear what "recursive" means to you. Usually, a recursive template approach is rather trivial in XSLT, but obviously, it is rather non-trivial to invent what you might mean by "recursive" as it may have many meanings.


If you need to calculate the sum of all unitPrice from a certain level, arbitrarily deep, then you should use the following statement, assuming your context node is on the right (parent) level:

sum(.//unitPrice)

HTH,
Cheers,
-- Abel Braaksma

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.