473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Grouping on Multiple Field

Hi , I am generating XML file from Database as below..

Expand|Select|Wrap|Line Numbers
  1. <?xml version = '1.0'?>
  2. <T0019>
  3.    <IFTA_ACCOUNT>
  4.       <IFTA_CARRIER_ID_NUMBER>705</IFTA_CARRIER_ID_NUMBER>
  5.       <IFTA_LICENSE_NUMBER>631227666</IFTA_LICENSE_NUMBER>
  6.       <IFTA_BASE_COUNTRY>US</IFTA_BASE_COUNTRY>
  7.       <IFTA_BASE_STATE>AL</IFTA_BASE_STATE>
  8.       <IFTA_STATUS_CODE>0  </IFTA_STATUS_CODE>
  9.       <IFTA_STATUS_DATE>2009-01-01</IFTA_STATUS_DATE>
  10.       <IFTA_ISSUE_DATE>2009-01-01</IFTA_ISSUE_DATE>
  11.       <IFTA_EXPIRE_DATE>2009-12-01</IFTA_EXPIRE_DATE>
  12.       <IFTA_UPDATE_DATE>2008-12-30</IFTA_UPDATE_DATE>
  13.       <NAME_TYPE>LG</NAME_TYPE>
  14.       <NAME>K D L TRUCKING INC</NAME>
  15.       <ADDRESS_TYPE>PH</ADDRESS_TYPE>
  16.       <STREET_LINE_1>200 MARTIN LANE</STREET_LINE_1>
  17.       <CITY>OHATCHEE</CITY>
  18.       <STATE>AL</STATE>
  19.       <ZIP_CODE>36271</ZIP_CODE>     
  20.       <COUNTY>CALHOUN COUNTY</COUNTY>
  21.       <COUNTRY>US</COUNTRY>
  22.   </IFTA_ACCOUNT>
  23.  
  24.    <IFTA_ACCOUNT>
  25.       <IFTA_CARRIER_ID_NUMBER>705</IFTA_CARRIER_ID_NUMBER>
  26.       <IFTA_LICENSE_NUMBER>631227666</IFTA_LICENSE_NUMBER>
  27.       <IFTA_BASE_COUNTRY>US</IFTA_BASE_COUNTRY>
  28.       <IFTA_BASE_STATE>AL</IFTA_BASE_STATE>
  29.       <IFTA_STATUS_CODE>0  </IFTA_STATUS_CODE>
  30.       <IFTA_STATUS_DATE>2009-01-01</IFTA_STATUS_DATE>
  31.       <IFTA_ISSUE_DATE>2009-01-01</IFTA_ISSUE_DATE>
  32.       <IFTA_EXPIRE_DATE>2009-12-01</IFTA_EXPIRE_DATE>
  33.       <IFTA_UPDATE_DATE>2008-12-30</IFTA_UPDATE_DATE>
  34.       <NAME_TYPE>LG</NAME_TYPE>
  35.       <NAME>K D L TRUCKING INC</NAME>
  36.       <ADDRESS_TYPE>MA</ADDRESS_TYPE>
  37.       <STREET_LINE_1>200 MARTIN LANE</STREET_LINE_1>
  38.       <CITY>OHATCHEE</CITY>
  39.       <STATE>AL</STATE>
  40.       <ZIP_CODE>36271</ZIP_CODE>
  41.       <COUNTRY>US</COUNTRY>
  42.     </IFTA_ACCOUNT>    
  43. </T0019>
Now I want to group the IFTA_ACCOUNT on IFTA_LICENSE_NUMBER,IFTA_BASE_COUNTRY and IFTA_BASE_STATE if they matches then it will look for Name Type if it will match then Address Details will be under Name Type

Here is the Desite Output....

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8" ?> 
  2.  <T0019>
  3.     <IFTA_ACCOUNT>
  4.       <IFTA_CARRIER_ID_NUMBER>705</IFTA_CARRIER_ID_NUMBER> 
  5.       <IFTA_BASE_COUNTRY>US</IFTA_BASE_COUNTRY> 
  6.       <IFTA_BASE_STATE>AL</IFTA_BASE_STATE> 
  7.       <IFTA_LICENSE_NUMBER>631227666</IFTA_LICENSE_NUMBER> 
  8.       <IFTA_STATUS_CODE>0</IFTA_STATUS_CODE> 
  9.       <IFTA_STATUS_DATE>2009-01-01</IFTA_STATUS_DATE> 
  10.       <IFTA_ISSUE_DATE>2009-01-01</IFTA_ISSUE_DATE> 
  11.       <IFTA_EXPIRE_DATE>2009-12-01</IFTA_EXPIRE_DATE> 
  12.       <IFTA_UPDATE_DATE>2008-12-30</IFTA_UPDATE_DATE> 
  13.      <IFTA_NAME>
  14.       <NAME_TYPE>LG</NAME_TYPE> 
  15.       <NAME>K D L TRUCKING INC</NAME> 
  16.          <IFTA_ADDRESS>
  17.               <ADDRESS_TYPE>PH</ADDRESS_TYPE> 
  18.               <STREET_LINE_1>200 MARTIN LANE</STREET_LINE_1> 
  19.               <STREET_LINE_2 /> 
  20.               <CITY>OHATCHEE</CITY> 
  21.               <STATE>AL</STATE> 
  22.               <ZIP_CODE>36271</ZIP_CODE> 
  23.               <COUNTY>CALHOUN COUNTY</COUNTY> 
  24.               <COUNTRY>US</COUNTRY> 
  25.           </IFTA_ADDRESS>
  26.          <IFTA_ADDRESS>
  27.               <ADDRESS_TYPE>MA</ADDRESS_TYPE> 
  28.               <STREET_LINE_1>200 MARTIN LANE</STREET_LINE_1> 
  29.               <STREET_LINE_2 /> 
  30.               <CITY>OHATCHEE</CITY> 
  31.               <STATE>AL</STATE> 
  32.               <ZIP_CODE>36271</ZIP_CODE> 
  33.               <COUNTY /> 
  34.               <COUNTRY>US</COUNTRY> 
  35.           </IFTA_ADDRESS>
  36.       </IFTA_NAME>
  37.   </IFTA_ACCOUNT>
  38.    </T0019>
Thanks...
May 10 '10 #1
4 6064
jkmyoung
2,057 Expert 2GB
What technology are you using to modify the XML? If XSLT 1.0, look into Muenchian grouping. If XSLT 2.0, look into the for-each-group functions. If something else, please specify.
May 10 '10 #2
I am using XSLT 2.0
May 11 '10 #3
jkmyoung
2,057 Expert 2GB
I'm not an expert in xslt 2.0, but I'd think it'd look something like:
Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each-group select="IFTA_ACCOUNT" group-by="IFTA_LICENSE_NUMBER">
  2.   <xsl:variable name="license" select="current-grouping-key()"/>
  3.      <xsl:for-each-group select="current-group()/." group-by="IFTA_BASE_COUNTRY"> 
  4.     <xsl:variable name="country" select="current-grouping-key()"/>
  5. ...
I am however confused by your result: You state that you are grouping on IFTA_LICENSE_NUMBER,IFTA_BASE_COUNTRY and IFTA_BASE_STATE, but in your element at the base level, you have:
Expand|Select|Wrap|Line Numbers
  1.      <IFTA_CARRIER_ID_NUMBER>705</IFTA_CARRIER_ID_NUMBER>  
  2.       <IFTA_BASE_COUNTRY>US</IFTA_BASE_COUNTRY>  
  3.       <IFTA_BASE_STATE>AL</IFTA_BASE_STATE>  
  4.       <IFTA_LICENSE_NUMBER>631227666</IFTA_LICENSE_NUMBER>  
  5.       <IFTA_STATUS_CODE>0</IFTA_STATUS_CODE>  
  6.       <IFTA_STATUS_DATE>2009-01-01</IFTA_STATUS_DATE>  
  7.       <IFTA_ISSUE_DATE>2009-01-01</IFTA_ISSUE_DATE>  
  8.       <IFTA_EXPIRE_DATE>2009-12-01</IFTA_EXPIRE_DATE>  
  9.       <IFTA_UPDATE_DATE>2008-12-30</IFTA_UPDATE_DATE>  
Will those values automatically be the same if the first 3 match? Please clarify.
May 11 '10 #4
Thanks for reply jkmyoung,

I have solved this with Grouping

Expand|Select|Wrap|Line Numbers
  1. <xsl:stylesheet
  2.     version="2.0"
  3.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
  4.  
  5.     <xsl:template match="T0019">
  6.         <xsl:copy>
  7.             <xsl:for-each-group select="IFTA_ACCOUNT" group-by="IFTA_LICENSE_NUMBER">
  8.                 <xsl:for-each-group select="current-group()" group-by="IFTA_BASE_COUNTRY">
  9.                     <xsl:for-each-group select="current-group()" group-by="IFTA_BASE_STATE">
  10.                         <IFTA_ACCOUNT>
  11.                             <xsl:apply-templates select="IFTA_CARRIER_ID_NUMBER|IFTA_BASE_COUNTRY|IFTA_BASE_STATE|IFTA_LICENSE_NUMBER|IFTA_STATUS_CODE|IFTA_STATUS_DATE|IFTA_ISSUE_DATE|IFTA_EXPIRE_DATE|IFTA_UPDATE_DATE"/>
  12.                             <xsl:for-each-group select="current-group()" group-by="NAME_TYPE">
  13.                                 <IFTA_NAME>
  14.                                     <xsl:apply-templates select="NAME_TYPE|NAME"/>
  15.                                     <xsl:for-each select="current-group()">
  16.                                         <IFTA_ADDRESS>
  17.                                             <xsl:apply-templates select="ADDRESS_TYPE|STREET_LINE_1|STREET_LINE_2|CITY|STATE|ZIP_CODE|COUNTY|COUNTRY"/>                                            
  18.                                         </IFTA_ADDRESS>                                        
  19.                                     </xsl:for-each>                                    
  20.                                 </IFTA_NAME>
  21.                             </xsl:for-each-group>                            
  22.                         </IFTA_ACCOUNT>                        
  23.                     </xsl:for-each-group>                    
  24.                 </xsl:for-each-group>  
  25.             </xsl:for-each-group>
  26.         </xsl:copy>
  27.  
  28.     </xsl:template>
  29.     <xsl:template match="IFTA_CARRIER_ID_NUMBER">
  30.         <IFTA_CARRIER_ID_NUMBER>
  31.             <xsl:value-of select="."/>
  32.         </IFTA_CARRIER_ID_NUMBER>            
  33.     </xsl:template>       
  34.     <xsl:template match="IFTA_LICENSE_NUMBER">
  35.         <IFTA_LICENSE_NUMBER>
  36.             <xsl:value-of select="."/>
  37.         </IFTA_LICENSE_NUMBER>            
  38.     </xsl:template>   
  39.     <xsl:template match="IFTA_BASE_COUNTRY">
  40.         <IFTA_BASE_COUNTRY>
  41.             <xsl:value-of select="."/>
  42.         </IFTA_BASE_COUNTRY>                        
  43.     </xsl:template>   
  44.     <xsl:template match="IFTA_BASE_STATE">
  45.         <IFTA_BASE_STATE>
  46.             <xsl:value-of select="."/>
  47.         </IFTA_BASE_STATE>            
  48.     </xsl:template>   
  49.     <xsl:template match="IFTA_STATUS_CODE">
  50.         <IFTA_STATUS_CODE>
  51.             <xsl:value-of select="."/>
  52.         </IFTA_STATUS_CODE>            
  53.     </xsl:template>   
  54.     <xsl:template match="IFTA_STATUS_DATE">
  55.         <IFTA_STATUS_DATE>
  56.             <xsl:value-of select="."/> 
  57.         </IFTA_STATUS_DATE>            
  58.     </xsl:template>   
  59.     <xsl:template match="IFTA_ISSUE_DATE">
  60.         <IFTA_ISSUE_DATE>
  61.             <xsl:value-of select="."/>
  62.         </IFTA_ISSUE_DATE>            
  63.     </xsl:template>
  64.     <xsl:template match="IFTA_EXPIRE_DATE">
  65.         <IFTA_STATUS_DATE>
  66.             <xsl:value-of select="."/> 
  67.         </IFTA_STATUS_DATE>            
  68.     </xsl:template>   
  69.     <xsl:template match="IFTA_UPDATE_DATE">
  70.         <IFTA_ISSUE_DATE>
  71.             <xsl:value-of select="."/>
  72.         </IFTA_ISSUE_DATE>            
  73.     </xsl:template>    
  74.     <xsl:template match="NAME_TYPE">
  75.         <NAME_TYPE>
  76.             <xsl:value-of select="."/>
  77.         </NAME_TYPE>            
  78.     </xsl:template>
  79.     <xsl:template match="NAME">
  80.         <NAME_TYPE>
  81.             <xsl:value-of select="."/>
  82.         </NAME_TYPE>            
  83.     </xsl:template>     
  84.     <xsl:template match="ADDRESS_TYPE">
  85.         <ADDRESS_TYPE>
  86.             <xsl:value-of select="."/>
  87.         </ADDRESS_TYPE>            
  88.     </xsl:template>
  89.  
  90.     <xsl:template match="STREET_LINE_1">
  91.         <STREET_LINE_1>
  92.             <xsl:value-of select="."/>
  93.         </STREET_LINE_1>            
  94.     </xsl:template>
  95.     <xsl:template match="STREET_LINE_2">
  96.         <STREET_LINE_2>
  97.             <xsl:value-of select="."/>
  98.         </STREET_LINE_2>            
  99.     </xsl:template>
  100.     <xsl:template match="CITY">
  101.         <CITY>
  102.             <xsl:value-of select="."/> 
  103.         </CITY>            
  104.     </xsl:template>   
  105.     <xsl:template match="STATE">
  106.         <STATE>
  107.             <xsl:value-of select="."/>
  108.         </STATE>            
  109.     </xsl:template>    
  110.     <xsl:template match="ZIP_CODE">
  111.         <ZIP_CODE>
  112.             <xsl:value-of select="."/>
  113.         </ZIP_CODE>            
  114.     </xsl:template>  
  115.     <xsl:template match="COUNTY">
  116.         <COUNTY>
  117.             <xsl:value-of select="."/>
  118.         </COUNTY>            
  119.     </xsl:template>
  120.     <xsl:template match="COUNTRY">
  121.         <COUNTRY>
  122.             <xsl:value-of select="."/>
  123.         </COUNTRY>            
  124.     </xsl:template>    
  125. </xsl:stylesheet>

I will try with your solution also to best solution..

Thanks

Nisarg
May 11 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mark Creelman | last post by:
Hello all: How do I convert this ASP mailer script to accept and mail multiple fields of a form. This will do one field only )iMesg.TextBody = Request.Form("body") and it works great. Seems...
2
by: suzanne shelton | last post by:
Help! I have two tables that i am wishing to join that involve a multiple field primary key on the primary table. Primary table: ScheduleHistory SID *PK Schedule *PK Secondary...
1
by: Joe | last post by:
I have a table with a student id and course id. I would like to make both fields the primary key since a student can have multiple course ids but I do not want duplicate records. How would I go...
1
by: itm | last post by:
My boss has an Access 2002 db with 2 tables that each include almost 1,000,000 records. Their common demoninator is an account number. One of the tables has 10 column fields with jurisdiction...
3
by: veaux | last post by:
I have a table that looks like below: Name, Address, Favorite Pet Bill Smith, 123 Smith St, Dogs Bill Smith, 123 Smith St, Cats The "Dogs" and "Cats" are actually in a lookup table, but have...
2
by: vito | last post by:
I need help anybody knows how to group a query so I can get a count of all the same record in a field like a subtotal in excel.
2
by: dylanhughes | last post by:
I'm looking for an example of a login system that has multiple fields (2 to be exact) + password. e.g username, company name and password, the user, company and password are checked against a mysql...
10
by: FNA access | last post by:
Hello to the world of the wise, I am a CSOM student at TRU. I am trying to design a database to improve my understanding. The problem I am having is with setting up a query. I have a Query...
1
by: JackpipE | last post by:
I have 2 tables TABLE A | id | name | | 1 | John | | 2 | David | | 3 | Adam | TABLE B | id | colors | | 1 | blue |
3
by: Kevin Davis | last post by:
Hello, I have an quick question. I have the following form: <form action="<?php echo $_SERVER;?>" method="post" > <?php linecount = 5 ?> <?php for (i=0; i< linecount;i++)
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.