/ .. / / -> download
<?xml version='1.0'?>
<xsl:stylesheet version="1.1" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:fo="http://www.w3.org/1999/XSL/Format">
	<!-- 9/14/11 - kr - Made the pm ref in dmodules look like the dm ref format -->
	<!-- 8/19/11 - KR - added dmc to ids to make them unique in pubs -->
	<!-- 8/19/11 - KR - added link on dmRef to enable links on dmRefs in pubs -->
	
	<xsl:template match="internalRef">
		<!-- 3031 prohibits internal references to list. Added the following code to generate an error message if an internal reference points to a list item -->
		<xsl:choose>
			<xsl:when test="key('id',@internalRefId)/ancestor-or-self::listItem | key('id',@internalRefId)/ancestor-or-self::randomList | key('id',@internalRefId)/ancestor-or-self::sequentialList">
				<fo:block color="red">
					<xsl:text>Error: Internal reference to list element prohibited. </xsl:text>
				</fo:block>
			</xsl:when>
			<xsl:otherwise>
				<fo:basic-link>
					<!-- 8/19/11 - KR - added dmc to ids to make them unique in pubs -->
					<xsl:attribute name="internal-destination">
						<xsl:apply-templates select="//dmodule/identAndStatusSection/dmAddress/dmIdent/dmCode"/>											
						<xsl:value-of select="@internalRefId"/>
					</xsl:attribute>
					<xsl:variable name="targetElement" select="local-name(key('id',@internalRefId))"/>
					<xsl:for-each select="key('id',(@internalRefId))">
						<xsl:choose>
							<xsl:when test="$targetElement='figure'">
								<xsl:text disable-output-escaping="no">Figure </xsl:text>
								<xsl:number count="figure" from="content" level="any"/>
							</xsl:when>
							<xsl:when test="$targetElement='hotspot'">
								<xsl:text disable-output-escaping="no">Figure </xsl:text>
								<xsl:number count="figure" from="content" level="any"/>
								<xsl:if test="@hotspotType='CALLOUT'">
									<xsl:text>, Item </xsl:text>
									<xsl:value-of select="@applicationStructureName"/>
								</xsl:if>
							</xsl:when>
							<xsl:when test="$targetElement='table' or $targetElement='reqCondGroup' or $targetElement='reqSupportEquips' or $targetElement='reqSupplies' or $targetElement='reqSpares' or $targetElement='reqPersons' or $targetElement='reqTechInfoGroup'">								<xsl:text disable-output-escaping="no">Table </xsl:text>
								<xsl:call-template name="number-tables"></xsl:call-template>
							</xsl:when>
							<xsl:when test="$targetElement='levelledPara'">
								<xsl:text disable-output-escaping="no">Para </xsl:text>
								<xsl:number count="levelledPara" from="content" level="multiple" format="1.1.1.1.1"/>					
							</xsl:when>
							<xsl:when test="$targetElement='proceduralStep'">
								<xsl:text disable-output-escaping="no">Step </xsl:text>
								<xsl:number count="proceduralStep" from="content" level="multiple" format="1.1.1.1.1"/>					
							</xsl:when>
							<xsl:when test="$targetElement='supportEquipDescr'">
								<xsl:value-of select="name"/>
							</xsl:when>
							<xsl:when test="$targetElement='supplyDescr'">
								<xsl:value-of select="name"/>
							</xsl:when>
							<xsl:when test="$targetElement='spareDescr'">
								<xsl:value-of select="name"/>
							</xsl:when>
							<xsl:otherwise>
								<fo:inline color="red"><xsl:text>The Army does not allow an internal reference to </xsl:text><xsl:value-of select="$targetElement"/></fo:inline>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:for-each>
				</fo:basic-link>
				

			<!--	
				<fo:basic-link internal-destination="{@internalRefId}">
					<xsl:apply-templates mode="xref" select="key('id',@internalRefId)"/>
				</fo:basic-link>
				-->
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	
	<!-- From S1000D:
		References to data modules and technical publications are presented in lexical order, with data modules first, in the beginning of a data module under the caption "References".
		The references table is presented under the caption References (Centerhead 		No.2) as Table 1 with the table title References.		
		The table presents the data module code, the publication module code or a non S1000D 		publication code together with the corresponding title, as given by the element <refs>.
		The data module reference is derived from the element <dmRef>.
		The publication module reference is derived from the element <pmRef>.
		A non S1000D publication reference is derived from the element <externalPubRef> using the element <externalPubCode> and/or the element <externalPubTitle> contained in element <externalPubRefIdent>.
		The absence of the element <refs> will be presented with "None".
	--> 
		<xsl:template name="process-refs">
		<fo:block xsl:use-attribute-sets="centerhead2"><xsl:text>References</xsl:text></fo:block>
		<fo:block span="all">
			<fo:table-and-caption>
				<fo:table-caption>
					<fo:block font-weight="bold" 
						keep-with-previous.within-column="always"
						keep-with-previous.within-page="always" space-after.maximum="10pt"
						space-after.minimum="10pt" space-after.optimum="10pt"
						space-before.maximum="12pt" space-before.minimum="8pt"
						space-before.optimum="10pt" span="all" text-align="center">
						<xsl:text disable-output-escaping="no">Table 1  </xsl:text>
						<xsl:text> References</xsl:text>
					</fo:block>
				</fo:table-caption>
				<xsl:call-template name="refsTable"/>
			</fo:table-and-caption>
		</fo:block>
	</xsl:template>

	<xsl:template name="refsTable">
		<fo:table xsl:use-attribute-sets="standard.table.setup">
			<fo:table-column column-number="1" column-width="45%"/>
			<fo:table-column column-number="2" column-width="55%"/>
			<fo:table-header text-align="left" space-before="10pt" space-after="10pt"
				border-after-style="solid" border-after-width="0.25pt">
				<fo:table-row>
					<fo:table-cell  xsl:use-attribute-sets="table.cell.padding">
						<fo:block xsl:use-attribute-sets="column-title">Chap No./Document No.</fo:block>
					</fo:table-cell>
					<fo:table-cell  xsl:use-attribute-sets="table.cell.padding">
						<fo:block xsl:use-attribute-sets="column-title">Title</fo:block>
					</fo:table-cell>
				</fo:table-row>
			</fo:table-header>
			<fo:table-body>
				<xsl:choose>
					<xsl:when test="refs">
						<xsl:call-template name="SortDmRefs"/>
						<xsl:call-template name="SortPmRefs"/>
						<xsl:call-template name="SortExternalPubRefs"/>
					</xsl:when>
					<xsl:otherwise>
						<fo:table-row>
							<fo:table-cell  xsl:use-attribute-sets="table.cell.padding"><fo:block><xsl:text>None</xsl:text></fo:block></fo:table-cell>
						</fo:table-row>
					</xsl:otherwise>
				</xsl:choose>
			</fo:table-body>
		</fo:table>		
	</xsl:template>
	
	<xsl:template name="SortDmRefs">
		<xsl:for-each select="refs/dmRef/dmRefIdent/dmCode">
			<xsl:sort select="@modelIdentCode"/>
			<xsl:sort select="@systemDiffCode"/>
			<xsl:sort select="@systemCode"/>
			<xsl:sort select="@subSystemCode"/>
			<xsl:sort select="@subSubSystemCode"/>
			<xsl:sort select="@assycode"/>
			<xsl:sort select="@disassyCode"/>
			<xsl:sort select="@disassyCodeVariant"/>
			<xsl:sort select="@infoCode"/>
			<xsl:sort select="@infoCodeVariant"/>
			<xsl:sort select="@itemLocationCode"/>
			<fo:table-row>
				<fo:table-cell  xsl:use-attribute-sets="table.cell.padding">
					<fo:block>
						<xsl:value-of select="@modelIdentCode"/>
						<xsl:text>-</xsl:text>
						<xsl:value-of select="@systemDiffCode"/>
						<xsl:text>-</xsl:text>
						<xsl:value-of select="@systemCode"/>
						<xsl:text>-</xsl:text>
						<xsl:value-of select="@subSystemCode"/>
						<xsl:value-of select="@subSubSystemCode"/>
						<xsl:text>-</xsl:text>
						<xsl:value-of select="@assyCode"/>
						<xsl:text>-</xsl:text>
						<xsl:value-of select="@disassyCode"/>
						<xsl:value-of select="@disassyCodeVariant"/>
						<xsl:text>-</xsl:text>
						<xsl:value-of select="@infoCode"/>
						<xsl:value-of select="@infoCodeVariant"/>
						<xsl:text>-</xsl:text>
						<xsl:value-of select="@itemLocationCode"/>
					</fo:block>
				</fo:table-cell>
				<fo:table-cell  xsl:use-attribute-sets="table.cell.padding">
					<fo:block>
						<xsl:value-of select="ancestor::dmRef/dmRefAddressItems//techName"/>
						<xsl:text> - </xsl:text>
						<xsl:value-of select="ancestor::dmRef/dmRefAddressItems//infoName"/>
					</fo:block>
				</fo:table-cell>
			</fo:table-row>
		</xsl:for-each>
	</xsl:template>
	
	<xsl:template name="SortPmRefs">
		<xsl:for-each select="refs/pmRef/pmRefIdent/pmCode">
			<xsl:sort select="@modelIdentCode"/>
			<xsl:sort select="@pmNumber"/>
			<fo:table-row>
				<fo:table-cell  xsl:use-attribute-sets="table.cell.padding">
					<fo:block>
						<xsl:value-of select="@pmNumber"/>
					</fo:block>
				</fo:table-cell>
				<fo:table-cell  xsl:use-attribute-sets="table.cell.padding">
					<fo:block>
						<xsl:value-of select="ancestor::pmRef/pmRefAddressItems//pmTitle"/>
					</fo:block>
				</fo:table-cell>
			</fo:table-row>
		</xsl:for-each>	</xsl:template>

	<xsl:template name="SortExternalPubRefs">
		<xsl:for-each select="refs/externalPubRef">
			<xsl:sort select="externalPubRef/externalPubRefIdent/externalPubCode"/>
				<fo:table-row>
					<fo:table-cell  xsl:use-attribute-sets="table.cell.padding">
						<fo:block>
							<xsl:value-of select="externalPubRefIdent/externalPubCode"/>
						</fo:block>
					</fo:table-cell>
					<fo:table-cell  xsl:use-attribute-sets="table.cell.padding">
						<fo:block>
							<xsl:value-of select="externalPubRefIdent/externalPubTitle"/>
						</fo:block>
					</fo:table-cell>
				</fo:table-row>
		</xsl:for-each>
	</xsl:template>
	
	<xsl:template match="refs"/>
	
	<xsl:template match="/dmodule//*//dmRef">
		<fo:basic-link>
			<!-- 8/19/11 - KR - added link -->
			<xsl:attribute name="internal-destination">
				<xsl:apply-templates select="dmRefIdent/dmCode"/>											
			</xsl:attribute>
			<xsl:apply-templates select="dmRefAddressItems/dmTitle"/>
			<xsl:text> [</xsl:text>
			<xsl:apply-templates select="dmRefIdent/dmCode"/>
			<xsl:text>]</xsl:text>
		</fo:basic-link>
			
	</xsl:template>
	
	<xsl:template match="/dmodule//*//dmRefIdent">
		<xsl:apply-templates/>
	</xsl:template>

	<xsl:template match="dmRefAddressItems">
		<xsl:apply-templates/>
	</xsl:template>
	
	<xsl:template match="pmRef">
		<xsl:choose>
			<xsl:when test="ancestor::refs"/>
			<!-- 9/14/11 - kr - Made the pm ref in dmodules look like the dm ref format -->
			<xsl:when test="ancestor::dmodule">
				<xsl:apply-templates select="pmRefAddressItems/pmTitle"/>
				<xsl:text> [</xsl:text>
				<xsl:apply-templates select="pmRefIdent/pmCode"/>
				<xsl:text>] </xsl:text>			
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="pmRefIdent">
		<xsl:apply-templates/>
	</xsl:template>
	
	<!--beaslic, 03/01/2011, added template for pmRefAddressItems-->
	<xsl:template match="pmRefAddressItems">
		<xsl:apply-templates/>
	</xsl:template>

	<xsl:template match="pmCode">
		<xsl:value-of select="@modelIdentCode"/>
		<xsl:text>-</xsl:text>
		<xsl:value-of select="@pmIssuer"/>
		<xsl:text>-</xsl:text>
		<xsl:value-of select="@pmNumber"/>
		<xsl:text>-</xsl:text>
		<xsl:value-of select="@pmVolume"/>
	</xsl:template>
	
	<xsl:template match="externalPubRef">
		<xsl:choose>
			<xsl:when test="ancestor-or-self::refs"/>
			<xsl:otherwise>
				<xsl:apply-templates/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="externalPubRefIdent">
		<xsl:apply-templates/>
	</xsl:template>
	
	<xsl:template match="externalPubCode">
		<xsl:apply-templates/>
	</xsl:template>
	
	<xsl:template match="externalPubTitle">
		<xsl:choose>
			<xsl:when test="ancestor::toolRef"/>
			<xsl:otherwise>
				<xsl:text> </xsl:text>
				<xsl:apply-templates/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="toolRef">
		<xsl:text>Tool</xsl:text>
		<xsl:choose>
			<xsl:when test="@manufacturerCodeValue">
				<xsl:text>/MFR </xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text> </xsl:text>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:value-of select="@toolNumber"/>
		<xsl:if test="@manufacturerCodeValue">
			<xsl:value-of select="@manufacturerCodeValue"/>
		</xsl:if>
		<xsl:apply-templates/>
	</xsl:template>
	
	<xsl:template match="toolRef/refs">
		<xsl:apply-templates select="externalPubCode"/>
	</xsl:template>
	
	<xsl:template match="catalogSeqNumberRef">
		<xsl:choose>
			<xsl:when test="@itemSeqNumberValue">
				<xsl:text>CSN/ISN </xsl:text> 
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>CSN </xsl:text>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:value-of select="@catalogSeqNumberValue"/>
		<xsl:if test="@itemSeqNumberValue">
			<xsl:text>/</xsl:text>
			<xsl:value-of select="@itemSeqNumberValue"/>
		</xsl:if>
		<!--<xsl:if test="refs">
			<xsl:text> /</xsl:text>
			<fo:block/>
		</xsl:if>
		<xsl:apply-templates select="refs"/>-->
	</xsl:template>	
	
	<xsl:template match="catalogSeqNumberRef/refs">
		<xsl:apply-templates/>
	</xsl:template>
	
	<xsl:template match="controlIndicatorRef">
		<xsl:choose>
			<xsl:when test="ancestor::controlIndicatorRepository">
				<fo:basic-link internal-destination="{@controlIndicatorNumber}">
					<xsl:apply-templates select="key('id',@controlIndicatorNumber)"/>
					<xsl:value-of select="controlIndicatorName"/>
				</fo:basic-link>
			</xsl:when>
			<xsl:otherwise>
				<xsl:choose>
					<xsl:when test="child::refs/dmRef">
						<xsl:variable name="controlNumber">
							<xsl:value-of select="@controlIndicatorNumber"/>
						</xsl:variable>
						<xsl:variable name="externalFile">
							<xsl:text>DMC-</xsl:text>
							<xsl:apply-templates select="refs/dmRef"/>
							<xsl:choose>
								<xsl:when test="refs/dmRef/dmRefIdent/issueInfo">
									<xsl:text>_</xsl:text>
									<xsl:value-of select="//issueInfo/@issueNumber"/>
									<xsl:text>-</xsl:text>
									<xsl:value-of select="//issueInfo/@inWork"/>
									<xsl:text>_EN-US.xml</xsl:text>
								</xsl:when>
								<xsl:otherwise>
									<xsl:text>_001-00_EN-US.xml</xsl:text>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:variable>
						<xsl:variable name="externalFileNoSpace">
							<xsl:value-of select="normalize-space($externalFile)"/>
						</xsl:variable>
						<xsl:for-each select="document(translate($externalFileNoSpace,' ',''))/dmodule/content/techRepository/controlIndicatorRepository/controlIndicatorGroup/controlIndicatorSpec">
							<xsl:if test="@controlIndicatorNumber=$controlNumber">
								<fo:inline text-transform="lowercase">
									<xsl:value-of select="controlIndicatorName"/>
								</fo:inline>
							</xsl:if>
						</xsl:for-each>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="@controlIndicatorNumber"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>


/ gopher://khzae.net/0/s1kd/links/projects/3031/sample/PhunGun/CSDB/FO-3031-A00-S1000DGUN-REFS_001-00_EN-US.xsl
Styles: Light Dark Classic