<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xalan="http://xml.apache.org/xalan" xmlns:svg="http://www.w3.org/2000/svg" xmlns:fox="http://xml.apache.org/fop/extensions">
	<xsl:output method="xml"/>

	<xsl:template match="VEHICLES">
		<!-- global section -->

		<fo:root>


			<fo:layout-master-set>

				<fo:simple-page-master master-name="all" page-height="11.0in" page-width="8.5in" margin-top="0.5in" margin-bottom="0.5in" margin-left="0.5in" margin-right="0.5in">

					<fo:region-body margin-top="1.0in" margin-bottom="1.0in"/>

					<fo:region-before extent="1.2in"/>

					<fo:region-after extent="0.5in"/>
				</fo:simple-page-master>
			</fo:layout-master-set>

			<xsl:variable name="vNodeSet">
				<xsl:copy-of select="/VEHICLES//VEHICLE"/>
				<!-- <xsl:copy-of select="//VEHICLES"/> -->
			</xsl:variable>

			<xsl:variable name="gNodeSet">
				<xsl:copy-of select="/VEHICLES/GROUP"/>
				<!-- <xsl:copy-of select="GROUP"/> -->
			</xsl:variable>

			<xsl:call-template name="groupSet">
				<xsl:with-param name="gNodeSet" select="xalan:nodeset($gNodeSet)"/>
				<xsl:with-param name="vNodeSet" select="xalan:nodeset($vNodeSet)"/>
				<xsl:with-param name="gId" select="number(1)"/>
			</xsl:call-template>


			<fo:page-sequence master-reference="all" format="i">


				<fo:static-content flow-name="xsl-region-before">

					<fo:table table-layout="fixed" width="100%" display-align="center">

						<fo:table-column column-width="proportional-column-width(1)"/>
						<fo:table-column column-width="2in"/>

						<fo:table-body>
							<fo:table-row>
								<fo:table-cell display-align="center">

									<fo:block text-align="start">

										<fo:external-graphic height="0.5in" src="url(http://extranet.inland-group.net/images/i-logo.gif)"/>

										<fo:external-graphic height="0.6in" src="url(http://extranet.inland-group.net/images/inlandgroup.gif)"/>
									</fo:block>
								</fo:table-cell>


								<fo:table-cell font-size="8pt" font-family="Arial,sans-serif" font-weight="bold" line-height="1em + 2pt">
									<fo:block>
										<!--
										<xsl:for-each select="xalan:nodeset($company)/COMPANY/EXTRA">
											<xsl:sort select="@ID" data-type="number"/>
											<fo:block text-align="end">
												<xsl:value-of select="."/>
											</fo:block>
										</xsl:for-each>
																		-->
									</fo:block>
								</fo:table-cell>
							</fo:table-row>
							<fo:table-row>
								<fo:table-cell number-columns-spanned="2">
									<!--
									<fo:block>
										<xsl:value-of select="$heading"/>
									</fo:block> -->
								</fo:table-cell>
							</fo:table-row>
							<fo:table-row>
								<fo:table-cell number-columns-spanned="2">
									<fo:block>
										<fo:leader leader-length="7.5in" leader-pattern="rule" rule-thickness="2pt" color="#F7C600"/>
									</fo:block>
								</fo:table-cell>
							</fo:table-row>
						</fo:table-body>
					</fo:table>
				</fo:static-content>

				<fo:flow flow-name="xsl-region-body">

					<xsl:call-template name="output">
						<xsl:with-param name="gNodeSet" select="xalan:nodeset($gNodeSet)"/>
						<xsl:with-param name="vNodeSet" select="xalan:nodeset($vNodeSet)"/>
						<xsl:with-param name="gId" select="number(1)"/>
					</xsl:call-template>
				</fo:flow>
			</fo:page-sequence>
		</fo:root>
	</xsl:template>

	<xsl:template name="groupSet">
		<xsl:param name="gNodeSet"/>
		<xsl:param name="vNodeSet"/>
		<xsl:param name="gId"/>

		<xsl:variable name="grpCount" select="count(xalan:nodeset($gNodeSet)/GROUP/GROUP)"/>
		<xsl:variable name="nGid" select="$gId + 1"/>


		<xsl:choose>
			<xsl:when test="$grpCount != 0">
				<xsl:variable name="newGNodeSet">
					<xsl:copy-of select="xalan:nodeset($gNodeSet)/GROUP/GROUP"/>
				</xsl:variable>
				<xsl:variable name="gAtr" select="xalan:nodeset($gNodeSet)/GROUP/@NAME"/>
				<xsl:for-each select="xalan:nodeset($gNodeSet)/GROUP/ATTRIBUTE">
					<xsl:variable name="gVal" select="@VALUE"/>
					<xsl:variable name="pos" select="position()"/>
					<fox:outline internal-destination="{$gId}">
						<fox:label>
							<xsl:value-of select="$gVal"/>
						</fox:label>

						<xsl:variable name="newVNodeSet">
							<xsl:copy-of select="xalan:nodeset($vNodeSet)//VEHICLE[ATTRIBUTE[@NAME = $gAtr and @VALUE = $gVal]]"/>
						</xsl:variable>
						<xsl:call-template name="groupSet">
							<xsl:with-param name="gNodeSet" select="xalan:nodeset($newGNodeSet)"/>
							<xsl:with-param name="vNodeSet" select="xalan:nodeset($newVNodeSet)"/>
							<xsl:with-param name="gId" select="$nGid"/>
						</xsl:call-template>
					</fox:outline>
				</xsl:for-each>
			</xsl:when>
			<xsl:otherwise>
				<xsl:variable name="gAtr" select="xalan:nodeset($gNodeSet)/GROUP/@NAME"/>
				<xsl:for-each select="xalan:nodeset($gNodeSet)/GROUP/ATTRIBUTE">
					<xsl:variable name="gPos" select="position()"/>
					<xsl:variable name="gVal" select="@VALUE"/>
					<fox:outline internal-destination="{$gId}-{$gPos}">
						<fox:label>
							<xsl:value-of select="$gVal"/>
						</fox:label>
						<xsl:for-each select="xalan:nodeset($vNodeSet)/VEHICLE[ATTRIBUTE[@NAME = $gAtr and @VALUE = $gVal]]">
							<xsl:variable name="pos" select="position()"/>
							<fox:outline internal-destination="{$gId}-{$gPos}-{$pos}">
								<fox:label>
									<xsl:value-of select="ATTRIBUTE[@NAME = 'KEY']/@VALUE"/>
								</fox:label>
							</fox:outline>
						</xsl:for-each>
					</fox:outline>
				</xsl:for-each>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>


	<xsl:template name="output">
		<xsl:param name="gNodeSet"/>
		<xsl:param name="vNodeSet"/>
		<xsl:param name="gId"/>

		<xsl:variable name="grpCount" select="count(xalan:nodeset($gNodeSet)/GROUP/GROUP)"/>
		<xsl:variable name="nGid" select="$gId + 1"/>


		<xsl:choose>
			<xsl:when test="$grpCount != 0">
				<xsl:variable name="newGNodeSet">
					<xsl:copy-of select="xalan:nodeset($gNodeSet)/GROUP/GROUP"/>
				</xsl:variable>
				<xsl:variable name="gAtr" select="xalan:nodeset($gNodeSet)/GROUP/@NAME"/>
				<xsl:for-each select="xalan:nodeset($gNodeSet)/GROUP/ATTRIBUTE">
					<xsl:variable name="gVal" select="@VALUE"/>
					<xsl:variable name="pos" select="position()"/>

					<xsl:variable name="newVNodeSet">
						<xsl:copy-of select="xalan:nodeset($vNodeSet)//VEHICLE[ATTRIBUTE[@NAME = $gAtr and @VALUE = $gVal]]"/>
					</xsl:variable>
					<xsl:call-template name="output">
						<xsl:with-param name="gNodeSet" select="xalan:nodeset($newGNodeSet)"/>
						<xsl:with-param name="vNodeSet" select="xalan:nodeset($newVNodeSet)"/>
						<xsl:with-param name="gId" select="$nGid"/>
					</xsl:call-template>
				</xsl:for-each>
			</xsl:when>
			<xsl:otherwise>
				<xsl:variable name="gAtr" select="xalan:nodeset($gNodeSet)/GROUP/@NAME"/>
				<xsl:for-each select="xalan:nodeset($gNodeSet)/GROUP/ATTRIBUTE">
					<xsl:variable name="gPos" select="position()"/>
					<xsl:variable name="gVal" select="@VALUE"/>
					<xsl:for-each select="xalan:nodeset($vNodeSet)/VEHICLE[ATTRIBUTE[@NAME = $gAtr and @VALUE = $gVal]]">
						<xsl:variable name="src" select="ATTRIBUTE[@NAME = 'KEY']/@VALUE"/>
						<xsl:variable name="pos" select="position()"/>
						<xsl:variable name="pos" select="position()"/>
						<fo:block space-after="0.25in" id="{$gId}-{$gPos}-{$pos}">
							<fo:table table-layout="fixed" width="100%" display-align="center">
								<fo:table-column column-width="1.0in"/>
								<fo:table-column column-width="proportional-column-width(1)"/>
								<fo:table-body>
									<fo:table-row keep-together="always" vertical-align="top">
										<fo:table-cell>
											<fo:external-graphic width="0.8in" src="url(http://extranet.inland-group.net/vsearch/images/vehicles/ImageUtil2.aspx?src={$src}&amp;height=150&amp;width=150)"/>
										</fo:table-cell>
										<fo:table-cell>
											<fo:block>
												<xsl:for-each select="ATTRIBUTE[@VALUE != '' and @SHOW != '']">
													<!-- <xsl:for-each select="ATTRIBUTE"> -->
													<xsl:if test="position() != 1">
														<xsl:text>, </xsl:text>
													</xsl:if>
													<xsl:value-of select="@VALUE"/>
												</xsl:for-each>
											</fo:block>
										</fo:table-cell>
									</fo:table-row>
								</fo:table-body>
							</fo:table>
						</fo:block>
					</xsl:for-each>
				</xsl:for-each>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c)1998-2003. Sonic Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Vehicle Index Report" userelativepaths="yes" externalpreview="no" url="VEH4.XML" htmlbaseurl="" outputurl="..\My Documents\xsl\test.fo" processortype="xalan" profilemode="0" urlprofilexml="" commandline="" additionalpath="c:\javalibs;c:\work" additionalclasspath="c:\javalibs\xalan&#x2D;2.5.0.jar" postprocessortype="fop" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext=""/></scenarios><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
</metaInformation>
-->