Re: [xsl] Sort, group, flatten, consecutive data

Subject: Re: [xsl] Sort, group, flatten, consecutive data
From: JBryant@xxxxxxxxx
Date: Tue, 28 Jun 2005 16:47:02 -0500
Never mind the output bit. I see that I missed this in your first post:

Rough example of output:

<ROWS>
                 <ROW CONTRACT_ID="351" CONTRACT_NUMBER="555" 
DETAIL_ID="570"
BEGINDAY="3/1/2004" ENDDAY="3/2/2004" RATE="0.02"/>
                 <ROW CONTRACT_ID="351" CONTRACT_NUMBER="555" 
DETAIL_ID="570"
BEGINDAY="3/3/2004" ENDDAY="3/5/2004" RATE="0.01"/>
</ROWS>

This and my earlier posts prove that my mind is definitely elsewhere (I've 
been pretty tightly focused on my own coding problems lately).

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)




JBryant@xxxxxxxxx 
06/28/2005 04:40 PM
Please respond to
xsl-list@xxxxxxxxxxxxxxxxxxxxxx


To
xsl-list@xxxxxxxxxxxxxxxxxxxxxx
cc

Subject
Re: [xsl] Sort, group, flatten, consecutive data






Hi, Robert,

Welcome to the XSL list.

Just the keywords in your subject line tell me that your post is on-topic, 

so you needn't apologize.

Grouping is one of those things that really depends on what are trying to 
achieve, so please post the XML you'd like your XSL to produce. With only 
the input to play with, I'd have to guess, which may just waste time and 
not give you what you need. Just offhand, I'd say you'll need to use keys 
or walk up and down the ancestor axis to get where you're going, but it's 
hard to be specific without seeing the desired output.

Also, as a small favor, could you use less indentation? I'm getting nasty 
wrapping when I view your source XML (partly because the mail client I 
have to use is dumb as a post). A couple spaces rather than a couple tabs 
would be much nicer.

Thanks.

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)




"Midnit" <midnit@xxxxxxxxxxxxxxxxx> 
06/28/2005 04:01 PM
Please respond to
xsl-list@xxxxxxxxxxxxxxxxxxxxxx


To
<xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
cc

Subject
[xsl] Sort, group, flatten, consecutive data






This is my first post here; I apologize if it's inappropriate.

I'm attempting to flatten and consolidate this XML document. In short I
would sort by DETAIL_ID and PRODUCTIONDAY, then group up based on the 
RATE,
outputting BEGINDAY and ENDDAY to represent the date range the RATE 
covered.
Though not shown in this example of data, there will be a record for every
day in the month so sorting by PRODUCTIONDAY will always produce 
consecutive
rows. I have no problem flattening the data but the attempts I've made at
grouping the data have failed miserably. All the examples I have found use
preceding-sibling and following-sibling which doesn't apply for my data, 
at
least that's my assumption. I have also tried using keys but I have run 
into
similar problems.

I am using XSLT 1.0.

Any suggestions would be greatly appreciated. What is the equiv of
following-sibling for my DETAIL_ID's?

<?xml version='1.0'?>
<BUSINESSASSOCIATE>
                 <ID>116</ID>
                 <SUPPLYCONTRACTS>
                                 <CONTRACT number='555'>
                                                 <ID>351</ID>
                                                 <DAYS>
                                                                 <DATE>
  <DAY>3/5/2004</DAY>
  <VERSIONS>
                 <VERSION>
                                 <DETAILS>
                                                 <DETAIL>
 
<DETAIL_ID>570</DETAIL_ID>
 
<PRODUCTIONDAY>5</PRODUCTIONDAY>
 
<PRODUCTIONDATE>3/5/2004</PRODUCTIONDATE>
 
<RESERVATION>
 
<RATE>0.01</RATE>
 
</RESERVATION>
                                                 </DETAIL>
                                 </DETAILS>
                 </VERSION>
  </VERSIONS>
                                                                 </DATE>
                                                                 <DATE>
  <DAY>3/4/2004</DAY>
  <VERSIONS>
                 <VERSION>
                                 <DETAILS>
                                                 <DETAIL>
 
<DETAIL_ID>570</DETAIL_ID>
 
<PRODUCTIONDAY>4</PRODUCTIONDAY>
 
<PRODUCTIONDATE>3/4/2004</PRODUCTIONDATE>
 
<RESERVATION>
 
<RATE>0.01</RATE>
 
</RESERVATION>
                                                 </DETAIL>
                                 </DETAILS>
                 </VERSION>
  </VERSIONS>
  </DATE>
                                                                 <DATE>
  <DAY>3/3/2004</DAY>
  <VERSIONS>
                 <VERSION>
                                 <DETAILS>
                                                 <DETAIL>
 
<DETAIL_ID>570</DETAIL_ID>
 
<PRODUCTIONDAY>3</PRODUCTIONDAY>
 
<PRODUCTIONDATE>3/3/2004</PRODUCTIONDATE>
 
<RESERVATION>
 
<RATE>0.01</RATE>
 
</RESERVATION>
                                                 </DETAIL>
                                 </DETAILS>
                 </VERSION>
  </VERSIONS>
                                                                 </DATE>
                                                                 <DATE>
  <DAY>3/2/2004</DAY>
  <VERSIONS>
                 <VERSION>
                                 <DETAILS>
                                                 <DETAIL>
 
<DETAIL_ID>570</DETAIL_ID>
 
<PRODUCTIONDAY>2</PRODUCTIONDAY>
 
<PRODUCTIONDATE>3/2/2004</PRODUCTIONDATE>
 
<RESERVATION>
 
<RATE>0.02</RATE>
 
</RESERVATION>
                                                 </DETAIL>
                                 </DETAILS>
                 </VERSION>
  </VERSIONS>
                                                                 </DATE>
                                                                 <DATE>
  <DAY>3/1/2004</DAY>
  <VERSIONS>
                 <VERSION>
                                 <DETAILS>
                                                 <DETAIL>
 
<DETAIL_ID>570</DETAIL_ID>
 
<PRODUCTIONDAY>1</PRODUCTIONDAY>
 
<PRODUCTIONDATE>3/1/2004</PRODUCTIONDATE>
 
<RESERVATION>
 
<RATE>0.02</RATE>
 
</RESERVATION>
                                                 </DETAIL>
                                 </DETAILS>
                 </VERSION>
  </VERSIONS>
                                                                 </DATE>
                                                 </DAYS>
                                 </CONTRACT>
                 </SUPPLYCONTRACTS>
</BUSINESSASSOCIATE>

Rough example of output:

<ROWS>
                 <ROW CONTRACT_ID="351" CONTRACT_NUMBER="555" 
DETAIL_ID="570"
BEGINDAY="3/1/2004" ENDDAY="3/2/2004" RATE="0.02"/>
                 <ROW CONTRACT_ID="351" CONTRACT_NUMBER="555" 
DETAIL_ID="570"
BEGINDAY="3/3/2004" ENDDAY="3/5/2004" RATE="0.01"/>
</ROWS>

-Robert

Current Thread