[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] RE: FO - How to group and sort in XSL:FO on a sibling values


Subject: Re: [xsl] RE: FO - How to group and sort in XSL:FO on a sibling values
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxx>
Date: Thu, 13 Dec 2012 09:41:23 -0500

Hi Chris,

Grouping and sorting are much (much) easier in XSLT 2.0, which has
facilities specifically designed for grouping.

In XSLT 1.0, grouping and sorting in a single stylesheet can be quite
difficult.

So consider one or more of the following:

* Acquire and learn XSLT 2.0 (much less painful)
* Master the use of keys (xsl:key and the key() function) in XSLT 1.0
* Consider splitting your transformation into several passes

Your problem looks like one that should be tractable using keys, but
you haven't given us enough info to sketch out a specific solution.

Keys are covered in any decent XSLT 1.0 book. And we do answer
followup questions.

Cheers,
Wendell

On Thu, Dec 13, 2012 at 6:27 AM, Chris Booth
<Chris.Booth@xxxxxxxxxxxxxxxx> wrote:
> I have this data:
>
> Lines
>         Line
>                 Item
>                         ItemGroup = ABC
>         Line
>                 Item
>                         ItemGroup = DEF
>         Line
>                 Item
>                         ItemGroup = ABC
>         Line
>                 Item
>                         ItemGroup = GHI
>
>
> I have the logic to (appear to) sort
>
> Lines
>         Line
>                 Item
>                         ItemGroup = ABC
>         Line
>                 Item
>                         ItemGroup = ABC
>         Line
>                 Item
>                         ItemGroup = DEF
>         Line
>                 Item
>                         ItemGroup = GHI
>
>
> However, it's not a true sorted list as the XML is still in the orginal
order, therefore the the preceding-sibling does not match what the sorted list
is showing and I then can't say if the the GroupCode is the same don't display
the Code, only the other Line data.
>
> Cheers
>
>
> -----Original Message-----
> From: Chris Booth [mailto:Chris.Booth@xxxxxxxxxxxxxxxx]
> Sent: Thursday, December 13, 2012 10:31 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] XSL:FO - How to group and sort in XSL:FO on a sibling values
>
> Hi,
>
>  I am after a little (actually a lot ) bit guidance and help please.
>
> I am struggling with Axis on the Xpath and how to group and sort.
>
>  Using XSL:FO (1.0 on Xalan) I need to be able to group parts of my data
together and not show them where the match other entries
>
> From the XML below, I am looking for a way where I loop over Lines/Line and
based on the value in LineGroup/GroupCode, if it's the first occurance of that
LineGroup/GroupCode then display the GroupDescription.
>
>
>  I am trying all sorts of variations on the below but with no joy-
>
>
>  <xsl:if test="mainGroupCodes != preceding-sibling::*/mainGroupCodes">
>          DISPLAY GROUP DESC
>  </xsl:if>
>
>  REQUIRED OUTPUT:
>  Main Group One
>         LINE DATA
>         LINE DATA
>
> Main Group Two
>         LINE DATA
>         LINE DATA
>
>  Main Group Three
>         LINE DATA
>         LINE DATA
>
>
>
> SAMPLE XML:
>  <Lines Type="Quote">
>         <Line Type="Quote">
>                 <DocumentLine>1.00</DocumentLine>
>                 <LineGroup>14.00</LineGroup>
>                 <LineDisplaySequence>1</LineDisplaySequence>
>                 <mainGroupCodes>1</mainGroupCodes>
>                 <LineGroup>
>                         <GroupId>14.00</GroupId>
>                         <GroupCode>1</GroupCode>
>                         <GroupDescription>Main Group One</GroupDescription>
>                         <FloorGroup>1</FloorGroup>
>                         <CeilingGroup>2</CeilingGroup>
>
<SubGroupLineValueTotal>8000.00</SubGroupLineValueTotal>
>
<AllGroupLineValueTotal>8000.00</AllGroupLineValueTotal>
>                 </LineGroup>
>         </Line>
>         <Line Type="Quote">
>                 <DocumentLine>31.00</DocumentLine>
>                 <LineGroup>16.00</LineGroup>
>                 <LineDisplaySequence>10</LineDisplaySequence>
>                 <mainGroupCodes>3</mainGroupCodes>
>                 <LineGroup>
>                         <GroupId>16.00</GroupId>
>                         <GroupCode>3</GroupCode>
>                         <GroupDescription>Main Group
Three</GroupDescription>
>                         <FloorGroup>3</FloorGroup>
>                         <CeilingGroup>4</CeilingGroup>
>
<SubGroupLineValueTotal>518.00</SubGroupLineValueTotal>
>
<AllGroupLineValueTotal>3806.00</AllGroupLineValueTotal>
>                 </LineGroup>
>         </Line>
>         <Line Type="Quote">
>                 <DocumentLine>2.00</DocumentLine>
>                 <LineGroup>16.00</LineGroup>
>                 <LineDisplaySequence>11</LineDisplaySequence>
>                 <mainGroupCodes>3</mainGroupCodes>
>                 <LineGroup>
>                         <GroupId>16.00</GroupId>
>                         <GroupCode>3</GroupCode>
>                         <GroupDescription>Main Group
Three</GroupDescription>
>                         <FloorGroup>3</FloorGroup>
>                         <CeilingGroup>4</CeilingGroup>
>
<SubGroupLineValueTotal>518.00</SubGroupLineValueTotal>
>
<AllGroupLineValueTotal>3806.00</AllGroupLineValueTotal>
>                 </LineGroup>
>         </Line>
>         <Line Type="Quote">
>                 <DocumentLine>13.00</DocumentLine>
>                 <LineGroup>19.00</LineGroup>
>                 <LineDisplaySequence>12</LineDisplaySequence>
>                 <mainGroupCodes>4</mainGroupCodes>
>                 <LineGroup>
>                         <GroupId>19.00</GroupId>
>                         <GroupCode>4.1</GroupCode>
>                         <GroupDescription>Sub group 1</GroupDescription>
>                         <FloorGroup>4</FloorGroup>
>                         <CeilingGroup>5</CeilingGroup>
>
<SubGroupLineValueTotal>4960.00</SubGroupLineValueTotal>
>
<AllGroupLineValueTotal>7034.00</AllGroupLineValueTotal>
>                 </LineGroup>
>         </Line>
>         <Line Type="Quote">
>                 <DocumentLine>14.00</DocumentLine>
>                 <LineGroup>19.00</LineGroup>
>                 <LineDisplaySequence>13</LineDisplaySequence>
>                 <mainGroupCodes>4</mainGroupCodes>
>                 <LineGroup>
>                         <GroupId>19.00</GroupId>
>                         <GroupCode>4.1</GroupCode>
>                         <GroupDescription>Sub group 1</GroupDescription>
>                         <FloorGroup>4</FloorGroup>
>                         <CeilingGroup>5</CeilingGroup>
>
<SubGroupLineValueTotal>4960.00</SubGroupLineValueTotal>
>
<AllGroupLineValueTotal>7034.00</AllGroupLineValueTotal>
>                 </LineGroup>
>         </Line>
>         <Line Type="Quote">
>                 <DocumentLine>15.00</DocumentLine>
>                 <LineGroup>19.00</LineGroup>
>                 <LineDisplaySequence>14</LineDisplaySequence>
>                 <mainGroupCodes>4</mainGroupCodes>
>                 <LineGroup>
>                         <GroupId>19.00</GroupId>
>                         <GroupCode>4.1</GroupCode>
>                         <GroupDescription>Sub group 1</GroupDescription>
>                         <FloorGroup>4</FloorGroup>
>                         <CeilingGroup>5</CeilingGroup>
>
<SubGroupLineValueTotal>4960.00</SubGroupLineValueTotal>
>
<AllGroupLineValueTotal>7034.00</AllGroupLineValueTotal>
>                 </LineGroup>
>         </Line>
>         <Line Type="Quote">
>                 <DocumentLine>17.00</DocumentLine>
>                 <LineGroup>19.00</LineGroup>
>                 <LineDisplaySequence>15</LineDisplaySequence>
>                 <mainGroupCodes>4</mainGroupCodes>
>                 <LineGroup>
>                         <GroupId>19.00</GroupId>
>                         <GroupCode>4.1</GroupCode>
>                         <GroupDescription>Sub group 1</GroupDescription>
>                         <FloorGroup>4</FloorGroup>
>                         <CeilingGroup>5</CeilingGroup>
>
<SubGroupLineValueTotal>4960.00</SubGroupLineValueTotal>
>
<AllGroupLineValueTotal>7034.00</AllGroupLineValueTotal>
>                 </LineGroup>
>         </Line>
>         <Line Type="Quote">
>                 <DocumentLine>23.00</DocumentLine>
>                 <LineGroup>19.00</LineGroup>
>                 <LineDisplaySequence>16</LineDisplaySequence>
>                 <OriginalOrderLine>0.00</OriginalOrderLine>
>                 <mainGroupCodes>4</mainGroupCodes>
>                 <LineGroup>
>                         <GroupId>19.00</GroupId>
>                         <GroupCode>4.1</GroupCode>
>                         <GroupDescription>Sub group 1</GroupDescription>
>                         <FloorGroup>4</FloorGroup>
>                         <CeilingGroup>5</CeilingGroup>
>
<SubGroupLineValueTotal>4960.00</SubGroupLineValueTotal>
>
<AllGroupLineValueTotal>7034.00</AllGroupLineValueTotal>
>                 </LineGroup>
>         </Line>
>         <Line Type="Quote">
>                 <DocumentLine>24.00</DocumentLine>
>                 <LineGroup>20.00</LineGroup>
>                 <LineDisplaySequence>17</LineDisplaySequence>
>                 <mainGroupCodes>4</mainGroupCodes>
>                 <LineGroup>
>                         <GroupId>20.00</GroupId>
>                         <GroupCode>4.2</GroupCode>
>                         <GroupDescription>Subgroup 2</GroupDescription>
>                         <FloorGroup>4</FloorGroup>
>                         <CeilingGroup>5</CeilingGroup>
>
<SubGroupLineValueTotal>0.00</SubGroupLineValueTotal>
>
<AllGroupLineValueTotal>7034.00</AllGroupLineValueTotal>
>                 </LineGroup>
>         </Line>
>         <Line Type="Quote">
>                 <DocumentLine>25.00</DocumentLine>
>                 <LineGroup>20.00</LineGroup>
>                 <LineDisplaySequence>18</LineDisplaySequence>
>                 <mainGroupCodes>4</mainGroupCodes>
>                 <LineGroup>
>                         <GroupId>20.00</GroupId>
>                         <GroupCode>4.2</GroupCode>
>                         <GroupDescription>Subgroup 2</GroupDescription>
>                         <FloorGroup>4</FloorGroup>
>                         <CeilingGroup>5</CeilingGroup>
>
<SubGroupLineValueTotal>0.00</SubGroupLineValueTotal>
>
<AllGroupLineValueTotal>7034.00</AllGroupLineValueTotal>
>                 </LineGroup>
>         </Line>
>         <Line Type="Quote">
>                 <DocumentLine>9.00</DocumentLine>
>                 <LineGroup>21.00</LineGroup>
>                 <LineDisplaySequence>19</LineDisplaySequence>
>                 <mainGroupCodes>4</mainGroupCodes>
>                 <LineGroup>
>                         <GroupId>21.00</GroupId>
>                         <GroupCode>4.3</GroupCode>
>                         <GroupDescription>Sub group 3</GroupDescription>
>                         <FloorGroup>4</FloorGroup>
>                         <CeilingGroup>5</CeilingGroup>
>
<SubGroupLineValueTotal>500.00</SubGroupLineValueTotal>
>
<AllGroupLineValueTotal>7034.00</AllGroupLineValueTotal>
>                 </LineGroup>
>         </Line>
>         <Line Type="Quote">
>                 <DocumentLine>20.00</DocumentLine>
>                 <LineGroup>14.00</LineGroup>
>                 <LineDisplaySequence>2</LineDisplaySequence>
>                 <mainGroupCodes>1</mainGroupCodes>
>                 <LineGroup>
>                         <GroupId>14.00</GroupId>
>                         <GroupCode>1</GroupCode>
>                         <GroupDescription>Main Group One</GroupDescription>
>                         <FloorGroup>1</FloorGroup>
>                         <CeilingGroup>2</CeilingGroup>
>
<SubGroupLineValueTotal>8000.00</SubGroupLineValueTotal>
>
<AllGroupLineValueTotal>8000.00</AllGroupLineValueTotal>
>                 </LineGroup>
>         </Line>
>         <Line Type="Quote">
>                 <DocumentLine>8.00</DocumentLine>
>                 <LineGroup>18.00</LineGroup>
>                 <LineDisplaySequence>20</LineDisplaySequence>
>                 <mainGroupCodes>4</mainGroupCodes>
>                 <LineGroup>
>                         <GroupId>18.00</GroupId>
>                         <GroupCode>4</GroupCode>
>                         <GroupDescription>Main Group 4</GroupDescription>
>                         <FloorGroup>4</FloorGroup>
>                         <CeilingGroup>5</CeilingGroup>
>
<SubGroupLineValueTotal>1574.00</SubGroupLineValueTotal>
>
<AllGroupLineValueTotal>7034.00</AllGroupLineValueTotal>
>                 </LineGroup>
>         </Line>
>  </Lines>
>
> *** This e-mail has been scanned for all viruses by MessageLabs. ***
>
> *** This e-mail has been scanned for all viruses by MessageLabs. ***
>
> *** This e-mail has been scanned for all viruses by MessageLabs. ***
>



--
Wendell Piez | http://www.wendellpiez.com
XML | XSLT | electronic publishing
Eat Your Vegetables
_____oo_________o_o___ooooo____ooooooo_^


Current Thread
Keywords