xsl-list
[Top] [All Lists]

RE: [xsl] FW: Sort on multiple key

2008-05-20 08:13:46
Yes I read the book regarding Muenchian grouping but I couldn't get my
head round it for my case. Unfortunately I only use XSLT rarely.
Regards
        Jan

-----Original Message-----
From: Michael Kay [mailto:mike(_at_)saxonica(_dot_)com] 
Sent: 20 May 2008 16:01
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] FW: Sort on multiple key

Sorting changes the order in which you process the nodes but it doesn't
change their position in the tree. So any use of XPath axes will reflect
the
original order of the nodes.

If you're using XSLT 2.0 you can solve this very easily using
xsl:for-each-group group-adjacent="...". With 1.0 it's rather harder.
Use
Muenchian grouping to identify the groups, then process the groups in
sorted
order.

Michael Kay
http://www.saxonica.com/

-----Original Message-----
From: Hesselberth, Jan 
[mailto:Jan(_dot_)Hesselberth(_at_)northernrock(_dot_)co(_dot_)uk] 
Sent: 20 May 2008 15:22
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] FW: Sort on multiple key

Ok I've managed to get my sort working.
I'm trying to produce a PDF document using fop. When printing 
a line need to determine if the customer name is the same as 
the previous line.
If it is I only want to print some values otherwise all 
values. However I cant get the test for the previous value of 
the customerName to work.
Any assistance would be helpful.
Regards
      Jan


                              <xsl:for-each
select="REPORT/Rollover/RolloverForecast/summaryAccount/elemen
t/rollover
Date">
                                      <xsl:sort select="."
order="ascending" data-type="text"/>
                                      <xsl:sort
select="concat(substring(translate(ancestor::summaryAccount/mf
AccountNo,
'&#09;',''),1,5),substring(translate(ancestor::summaryAccount/
mfAccountN
o,'&#09;',''),8,5),substring(translate(ancestor::summaryAccoun
t/mfAccoun
tNo,'&#09;',''),6,2))" order="ascending" data-type="text"/>
                                      <xsl:for-each
select="ancestor::element">
                                      <fo:table-row
keep-with-previous="keep">
                                              <xsl:choose>

                                                      <xsl:when
test="preceding::rolloverDate/ancestor::summaryAccount/custome
rName = ancestor::customerName">
      
<fo:table-cell keep-with-previous="keep">
      
<fo:block space-before.optimum="5pt" space-after.optimum="5pt"
font-size="10pt" text-align="left">
      
</fo:block>
      
</fo:table-cell>
      
<fo:table-cell>
      
<fo:block space-before.optimum="5pt" space-after.optimum="5pt"
font-size="10pt" text-align="end">    
      
</fo:block>
      
</fo:table-cell>
      
<fo:table-cell>
      
<fo:block space-before.optimum="5pt" space-after.optimum="5pt"
font-size="10pt" text-align="end">
      
</fo:block>
      
</fo:table-cell>
                                                      </xsl:when>
                                                      <xsl:otherwise>
      
<fo:table-cell keep-with-previous="keep">
      
<fo:block space-before.optimum="5pt" space-after.optimum="5pt"
font-size="10pt" text-align="left">
      
<xsl:value-of select="preceding-sibling::customerName"/>
      
</fo:block>
      
</fo:table-cell>
      
<fo:table-cell>
      
<fo:block space-before.optimum="5pt" space-after.optimum="5pt"
font-size="10pt" text-align="end">
      
<xsl:value-of select="preceding-sibling::mfAccountNo"/>
      
</fo:block>
      
</fo:table-cell>
      
<fo:table-cell>
      
<fo:block space-before.optimum="5pt" space-after.optimum="5pt"
font-size="10pt" text-align="end">
      
<xsl:value-of select="parent::summaryAccount/@id"/>
      
</fo:block>
      
</fo:table-cell>
                                                      </xsl:otherwise>
                                              </xsl:choose>
-----Original Message-----
From: Hesselberth, Jan
Sent: 20 May 2008 11:15
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Sort on multiple key

I have the xml below which needs to be sorted into key1 key2 order.
I can sort it in key1 order ok but can't get the key2 order. 
I tried this but it doesn't work.
I then need to be able to process the sorted xml by element.
Can you tell me where I'm going wrong please.
Regards
      Jan Hesselberth

<xsl:for-each select="SummaryNo/element/key1">
      <xsl:sort select="." order="ascending" data-type="text"/>
      <xsl:for-each select="ancestor::SummaryNo/key2">
              <xsl:sort select="." order="ascending"
data-type="text"/>
              <xsl:for-each select="preceding::element">




<SummaryNo id="123456789">
      <key2>12345K00348</key2>
      <customerName>Investments Limited</customerName>
      <element id="4">
              <key1>2008-04-16</key1>
              <rolloverResult>
                      <errorDescription>calculateInterestCharge
failed</errorDescription>
              </rolloverResult>
      </element>
      <element id="5">
              <key1>2008-04-16</key1>
              <rolloverResult>
                      <errorDescription>calculateInterestCharge
failed</errorDescription>
              </rolloverResult>
      </element>
      <element id="6">
              <key1>2008-04-18</key1>
              <rolloverResult>
                      <errorDescription>calculateInterestCharge
failed</errorDescription>
              </rolloverResult>
      </element>
</SummaryNo>
<SummaryNo id="234567890">
      <key2>56789D00172</key2>
      <customerName>Freds Developments Limited</customerName>
      <element id="4">
              <key1>2008-04-17</key1>
              <rolloverResult>
                      <errorDescription>calculateInterestCharge
failed</errorDescription>
              </rolloverResult>
      </element>
      <element id="5">
              <key1>2008-04-16</key1>
              <rolloverResult>
                      <errorDescription>calculateInterestCharge
failed</errorDescription>
              </rolloverResult>
      </element>
</SummaryNo>
<SummaryNo id="145678999">
      <key2>44551J00106</key2>
      <customerName>Housing Trust Limited</customerName>
      <element id="1">
              <key1>2008-04-16</key1>
              <rolloverResult>
                      <errorDescription>calculateInterestCharge
failed</errorDescription>
              </rolloverResult>
      </element>
      <element id="2">
              <key1>2008-04-15</key1>
              <rolloverResult>
                      <errorDescription>calculateInterestCharge
failed</errorDescription>
              </rolloverResult>
      </element>
      <element id="3">
              <key1>2008-04-17</key1>
              <rolloverResult>
                      <errorDescription>calculateInterestCharge
failed</errorDescription>
              </rolloverResult>
      </element>
</SummaryNo>


LEGAL NOTICE    The information contained in this e-mail and 
any attachments are private and confidential.  This message 
is solely intended for a particular recipient, if you are not 
the intended  recipient you are prohibited from storing, 
copying, disseminating or using the information  in any way.  
If you received this e-mail in error please notify the sender 
immediately.  E-mail transmission cannot be guaranteed to be 
secure or error-free as information could  be intercepted, 
corrupted, lost, destroyed, arrive late or incomplete, or 
contain viruses.  The sender therefore does not accept 
liability for any errors, viruses or omissions in the  
contents of this message, which arise as a result of 
transmission. This e-mail is not  intended to create legally 
binding commitments on behalf of Northern Rock plc, nor do 
its  contents reflect the corporate views or policies of 
Northern Rock plc.  Northern Rock plc,  Registered Office 
Northern Rock House Gosforth Newcastle upon Tyne NE3 4PL.  
Registered in England, number 3273685. Telephone No: 0191 
2857191  Northern Rock plc is authorised and regulated by the 
Financial Services Authority for  deposit-taking; advising on 
and arranging mortgages and general insurance; and for  
introducing life assurance and investments.

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit 
http://www.messagelabs.com/email 
______________________________________________________________________

--~------------------------------------------------------------------
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>
--~--



--~------------------------------------------------------------------
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>
--~--



LEGAL NOTICE 


The information contained in this e-mail and any attachments are private and 
confidential. 
This message is solely intended for a particular recipient, if you are not the 
intended 
recipient you are prohibited from storing, copying, disseminating or using the 
information 
in any way.  If you received this e-mail in error please notify the sender 
immediately. 
E-mail transmission cannot be guaranteed to be secure or error-free as 
information could 
be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or 
contain viruses. 
The sender therefore does not accept liability for any errors, viruses or 
omissions in the 
contents of this message, which arise as a result of transmission. This e-mail 
is not 
intended to create legally binding commitments on behalf of Northern Rock plc, 
nor do its 
contents reflect the corporate views or policies of Northern Rock plc.

Northern Rock plc, 
Registered Office Northern Rock House Gosforth Newcastle upon Tyne NE3 4PL. 
Registered in England, number 3273685. Telephone No: 0191 2857191

Northern Rock plc is authorised and regulated by the Financial Services 
Authority for 
deposit-taking; advising on and arranging mortgages and general insurance; and 
for 
introducing life assurance and investments.

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>