Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 13th, 2009, 02:55 PM
Registered User
 
Join Date: May 2008
Location: , , USA.
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
Reply With Quote
  #2 (permalink)  
Old February 13th, 2009, 06:16 PM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 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
Reply With Quote
  #3 (permalink)  
Old February 16th, 2009, 10:06 AM
Registered User
 
Join Date: May 2008
Location: , , USA.
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
Reply With Quote
  #4 (permalink)  
Old February 16th, 2009, 10:23 AM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 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
Reply With Quote
  #5 (permalink)  
Old February 17th, 2009, 01:53 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
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
Reply With Quote
  #6 (permalink)  
Old February 17th, 2009, 07:27 PM
Registered User
 
Join Date: May 2008
Location: , , USA.
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?


Reply With Quote
  #7 (permalink)  
Old February 17th, 2009, 07:39 PM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 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
Reply With Quote
  #8 (permalink)  
Old February 18th, 2009, 12:18 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:40 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.