Re: [xsl] XSL:FO - How to group on a preceeding-sibling value

Subject: Re: [xsl] XSL:FO - How to group on a preceeding-sibling value
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 24 Jan 2012 15:39:56 -0500
Hi Chris,

If using XSLT 2.0 (and why not?), you should look up xsl:for-each-group, which as the name implies is designed to support grouping.

If you are using XSLT 1.0 and don't have this option, there are several others, all of which share a single characteristic: they are less graceful than xsl:for-each-group.

The method you are attempting might be one of them, except for one thing. XPath ($nodesetA != $nodesetB) returns true if any member of $nodesetA is unequal to any member of $nodesetB.

You want not(mainGroupCodes = preceding-sibling::*/mainGroupCodes), which returns false as long as the value of mainGroupCodes is equal to the value of any of preceding-sibling::*/mainGroupCodes.

There is a subtle but important difference there.

Cheers,
Wendell

On 1/24/2012 10:17 AM, Chris Booth wrote:
Hi,

I am after a litte bit guidance and help please.

Using XSL:FO I need to be able to group parts of my data together.

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 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 Three LINE DATA LINE DATA

Sub Group 1
	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>

-- ====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================

Current Thread