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
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--