Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 13th, 2009, 02:55 PM
Registered User
 
Join Date: May 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Adding similiar occurences with loop

How can I add similiar occurrences of a node in xslt:

Like


Abc 12.00
EFT 3
Abc 12.00
Eft 4
Abc 11
Eft 2

I want it to b

Abc 35
eft 9

Thankx in advance
 
Old February 13th, 2009, 06:16 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

1. What does your input look like?

2. Are you using XSLT 1.0 or 2.0? (Most things are easier in 2.0....)
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old February 16th, 2009, 10:06 AM
Registered User
 
Join Date: May 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

its something like

<PersVeh id="v1" LocationRef="" RatedDriverRef="d1">
<ItemIdInfo>
<InsurerId>1</InsurerId>
</ItemIdInfo>
<Coverage>
<CoverageCd>ATFEE</CoverageCd>
<CoverageDesc/>
<Deductible>
<FormatCurrencyAmt>
<Amt/>
</FormatCurrencyAmt>
<DeductibleTypeCd/>
</Deductible>
<CurrentTermAmt>
<Amt>0.50</Amt>
</CurrentTermAmt>
</Coverage>
<Coverage>
<CoverageCd>BI</CoverageCd>
<CoverageDesc/>
<Limit>
<FormatCurrencyAmt>
<Amt>15/30</Amt>
</FormatCurrencyAmt>
</Limit>
<Deductible>
<FormatCurrencyAmt>
<Amt/>
</FormatCurrencyAmt>
<DeductibleTypeCd/>
</Deductible>
<CurrentTermAmt>
<Amt>146.30</Amt>
</CurrentTermAmt>
</Coverage>
<Coverage>
<CoverageCd>CMP</CoverageCd>
<CoverageDesc/>
<Deductible>
<FormatCurrencyAmt>
<Amt/>
</FormatCurrencyAmt>
<DeductibleTypeCd/>
</Deductible>
<CurrentTermAmt>
<Amt>96.50</Amt>
</CurrentTermAmt>
</Coverage>
<Coverage>
<CoverageCd>COL</CoverageCd>
<CoverageDesc/>
<Deductible>
<FormatCurrencyAmt>
<Amt/>
</FormatCurrencyAmt>
<DeductibleTypeCd/>
</Deductible>
<CurrentTermAmt>
<Amt>281.40</Amt>
</CurrentTermAmt>
</Coverage>
<Coverage>
<CoverageCd>MP</CoverageCd>
<CoverageDesc/>
<Limit>
<FormatCurrencyAmt>
<Amt>1</Amt>
</FormatCurrencyAmt>
</Limit>
<Deductible>
<FormatCurrencyAmt>
<Amt/>
</FormatCurrencyAmt>
<DeductibleTypeCd/>
</Deductible>
<CurrentTermAmt>
<Amt>16.50</Amt>
</CurrentTermAmt>
</Coverage>
<Coverage>
<CoverageCd>PD</CoverageCd>
<CoverageDesc/>
<Limit>
<FormatCurrencyAmt>
<Amt>10</Amt>
</FormatCurrencyAmt>
</Limit>
<Deductible>
<FormatCurrencyAmt>
<Amt/>
</FormatCurrencyAmt>
<DeductibleTypeCd/>
</Deductible>
<CurrentTermAmt>
<Amt>85.70</Amt>
</CurrentTermAmt>
</Coverage>
<Coverage>
<CoverageCd>RP</CoverageCd>
<CoverageDesc>Replacement Cost</CoverageDesc>
</Coverage>
<Coverage>
<CoverageCd>LL</CoverageCd>
<CoverageDesc>Loan / Lease GAP</CoverageDesc>
</Coverage>

</PersVeh>
<PersVeh id="v2" LocationRef="" RatedDriverRef="d1">
<ItemIdInfo>
<InsurerId>1</InsurerId>
</ItemIdInfo>
<Coverage>
<CoverageCd>ATFEE</CoverageCd>
<CoverageDesc/>
<Deductible>
<FormatCurrencyAmt>
<Amt/>
</FormatCurrencyAmt>
<DeductibleTypeCd/>
</Deductible>
<CurrentTermAmt>
<Amt>0.50</Amt>
</CurrentTermAmt>
</Coverage>
<Coverage>
<CoverageCd>BI</CoverageCd>
<CoverageDesc/>
<Limit>
<FormatCurrencyAmt>
<Amt>15/30</Amt>
</FormatCurrencyAmt>
</Limit>
<Deductible>
<FormatCurrencyAmt>
<Amt/>
</FormatCurrencyAmt>
<DeductibleTypeCd/>
</Deductible>
<CurrentTermAmt>
<Amt>146.30</Amt>
</CurrentTermAmt>
</Coverage>
<Coverage>
<CoverageCd>CMP</CoverageCd>
<CoverageDesc/>
<Deductible>
<FormatCurrencyAmt>
<Amt/>
</FormatCurrencyAmt>
<DeductibleTypeCd/>
</Deductible>
<CurrentTermAmt>
<Amt>96.50</Amt>
</CurrentTermAmt>
</Coverage>
<Coverage>
<CoverageCd>COL</CoverageCd>
<CoverageDesc/>
<Deductible>
<FormatCurrencyAmt>
<Amt/>
</FormatCurrencyAmt>
<DeductibleTypeCd/>
</Deductible>
<CurrentTermAmt>
<Amt>281.40</Amt>
</CurrentTermAmt>
</Coverage>
<Coverage>
<CoverageCd>MP</CoverageCd>
<CoverageDesc/>
<Limit>
<FormatCurrencyAmt>
<Amt>1</Amt>
</FormatCurrencyAmt>
</Limit>
<Deductible>
<FormatCurrencyAmt>
<Amt/>
</FormatCurrencyAmt>
<DeductibleTypeCd/>
</Deductible>
<CurrentTermAmt>
<Amt>16.50</Amt>
</CurrentTermAmt>
</Coverage>
<Coverage>
<CoverageCd>PD</CoverageCd>
<CoverageDesc/>
<Limit>
<FormatCurrencyAmt>
<Amt>10</Amt>
</FormatCurrencyAmt>
</Limit>
<Deductible>
<FormatCurrencyAmt>
<Amt/>
</FormatCurrencyAmt>
<DeductibleTypeCd/>
</Deductible>
<CurrentTermAmt>
<Amt>85.70</Amt>
</CurrentTermAmt>
</Coverage>
<Coverage>
<CoverageCd>RP</CoverageCd>
<CoverageDesc>Replacement Cost</CoverageDesc>
</Coverage>
<Coverage>
<CoverageCd>LL</CoverageCd>
<CoverageDesc>Loan / Lease GAP</CoverageDesc>
</Coverage>
</PersVeh>


and i want ATFEE 1
BI 296.4
on the basic of Coverage/CurrentTermAmt/Amt

Thankx
 
Old February 16th, 2009, 10:23 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>and i want ATFEE 1
BI 296.4
on the basic of Coverage/CurrentTermAmt/Amt

I'm sorry, if that's the requirement that you are working to, then I don't understand it.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old February 17th, 2009, 01:53 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

I don't know how you got the sum BI 296.4. Just check once.

With XSLT 2.0, try this:

Code:
 
<xsl:template match="root">

<xsl:variable name="node" select="//Amt"></xsl:variable>
<xsl:for-each select="distinct-values(//CoverageCd)">
<xsl:variable name="name">
<xsl:value-of select="."></xsl:value-of>
</xsl:variable>

<xsl:value-of select="$name"></xsl:value-of><xsl:text> = </xsl:text>
<xsl:value-of select="sum($node[../../CoverageCd = $name])"></xsl:value-of>
<xsl:text> </xsl:text>
</xsl:for-each>

</xsl:template>


__________________
Rummy
 
Old February 17th, 2009, 07:27 PM
Registered User
 
Join Date: May 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thankx Rummy,

But it is saying distinct-values() is an unknow xslt function.Even i have
<xsl:stylesheetxmlns:xsl="http://www.w3.org/1999/XSL/Transform"version="2.0">

on the top?


 
Old February 17th, 2009, 07:39 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You're probably using an XSLT processor that doesn't support XSLT 2.0 yet. Many don't. If you can use an XSLT 2.0 processor, your life will be much easier.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old February 18th, 2009, 12:18 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

As Mike has said, find the XSLT processor you are using. And also check whether it supports. When you run a XSLT 2.0 stylesheet with XSLT 1.0 processor, probably you might get an error message. Use latest version of Saxon processor which supports XSLT 2.0.
__________________
Rummy





Similar Threads
Thread Thread Starter Forum Replies Last Post
Count unique occurences Umasriram2 Excel VBA 2 May 28th, 2008 05:10 AM
Count string occurences across recordset goldstein SQL Server 2005 1 July 9th, 2007 06:47 PM
Consolidating multiple occurences in a single row ssray23 SQL Language 11 May 18th, 2007 11:00 AM
Count all occurences of a character in a string thomaz C# 2 February 9th, 2007 01:52 PM
How do you query for number of occurences? karjagis SQL Language 1 January 27th, 2005 10:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.