<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fm="http://www.itp-x.co.uk/xslt">

<!--
****************************************************************
* ADOBE SYSTEMS INCORPORATED                                   *
* Copyright 2006 © 2006 Adobe Systems Incorporated             *
* All Rights Reserved                                          *
*                                                              *
* NOTICE:  Adobe permits you to use, modify, and distribute    *
* this file in accordance with the terms of the Adobe license  *
* agreement accompanying it.  If you have received this file   *
* from a source other than Adobe, then your use, modification, *
* or distribution of it requires the prior written permission  *
* of Adobe.                                                    *
* _____________________________________________________________*
* Adobe FrameMaker 7.2 Application Pack for S1000D             *
*                                                              *
* Figure Import Transform                                      *
* Version   Date         By                                    *
* 0.2b      2006-08-21   Ian Proudfoot, iTP-X                  *
*                                                              *
****************************************************************
-->
	<xsl:template match="figure">
		<xsl:variable name="figt">
			<xsl:text>ft.</xsl:text>
			<xsl:value-of select="generate-id()"/>
		</xsl:variable>
		<xsl:element name="figure">
			<xsl:choose>
				<xsl:when test="@id=''">
					<xsl:attribute name="id">
						<xsl:value-of select="generate-id(.)"/>
					</xsl:attribute>
				</xsl:when>
				<xsl:when test="not(@id)">
					<xsl:attribute name="id">
						<xsl:value-of select="generate-id(.)"/>
					</xsl:attribute>
				</xsl:when>
				<xsl:otherwise>
					<xsl:copy-of select="@id"/>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:copy-of select="@mark"/>
			<xsl:copy-of select="@level"/>
			<xsl:copy-of select="@change"/>
			<xsl:copy-of select="@rfc"/>
			<xsl:for-each select="@class">
				<xsl:call-template name="class"/>
			</xsl:for-each>
			<xsl:for-each select="@caveat">
				<xsl:call-template name="caveat"/>
			</xsl:for-each>
			<xsl:for-each select="@commcls">
				<xsl:call-template name="commcls"/>
			</xsl:for-each>
			<xsl:copy-of select="applic[1]"/>
			<xsl:element name="fig-title">
				<xsl:attribute name="id">
					<xsl:value-of select="$figt"/>
				</xsl:attribute>
				<xsl:for-each select="title/@class">
					<xsl:call-template name="class"/>
				</xsl:for-each>
				<xsl:for-each select="title/@caveat">
					<xsl:call-template name="caveat"/>
				</xsl:for-each>
				<xsl:for-each select="title/@commcls">
					<xsl:call-template name="commcls"/>
				</xsl:for-each>
				<xsl:value-of select="title"/>
			</xsl:element>

			<xsl:choose>
				<xsl:when test="graphic[preceding-sibling::sheet]">
					<!--does graphic have multiple sheets?-->
					<xsl:for-each select="sheet">
						<xsl:element name="sheet">
							<xsl:copy-of select="@mark | @id | @change | @total | @sheetno | @rfc | @level"/>
							<xsl:for-each select="preceding-sibling::applic[1]">
								<xsl:copy-of select="."/>
							</xsl:for-each>
							<xsl:element name="fm:graphic">
								<xsl:for-each select="following-sibling::graphic[1]">
									<xsl:copy use-attribute-sets="graphic">
										<xsl:attribute name="boardno">
											<xsl:value-of select="unparsed-entity-uri(@boardno)"/>
										</xsl:attribute>
									</xsl:copy>
								</xsl:for-each>
								<xsl:element name="fm:title">
									<xsl:element name="fm:reftitle">
										<xsl:attribute name="title">
											<xsl:value-of select="$figt"/>
										</xsl:attribute>
									</xsl:element>
								</xsl:element>
								<xsl:for-each select="following-sibling::graphic[1]/hotspot">
									<xsl:copy-of select="."/>
								</xsl:for-each>
								<xsl:for-each select="following-sibling::graphic[1]">
									<xsl:variable name="rfa-id" select="generate-id()"/>
									<xsl:for-each select="following-sibling::rfa[generate-id(preceding-sibling::graphic[1]) = $rfa-id]">
										<xsl:copy-of select="."/>
									</xsl:for-each>
								</xsl:for-each>
							</xsl:element>
						</xsl:element>
					</xsl:for-each>
				</xsl:when>
				<xsl:when test="graphic[not(preceding-sibling::sheet)]">
					<!--Graphic does not have multiple sheets-->
					<xsl:element name="fm:graphic">
						<xsl:for-each select="graphic">
							<xsl:copy use-attribute-sets="graphic">
								<xsl:attribute name="boardno">
									<xsl:value-of select="unparsed-entity-uri(@boardno)"/>
								</xsl:attribute>
								<xsl:choose>
									<xsl:when test="@id=''"/>
									<xsl:when test="@id=' '"/>
									<xsl:when test="@id">
										<xsl:copy-of select="@id"/>
									</xsl:when>
								</xsl:choose>
							</xsl:copy>
						</xsl:for-each>
						<xsl:element name="fm:title">
							<xsl:element name="fm:reftitle">
								<xsl:attribute name="title">
									<xsl:value-of select="$figt"/>
								</xsl:attribute>
							</xsl:element>
						</xsl:element>
						<xsl:for-each select="graphic/hotspot">
							<xsl:copy-of select="."/>
						</xsl:for-each>
						<xsl:for-each select="graphic/rfa">
							<xsl:copy-of select="."/>
						</xsl:for-each>
					</xsl:element>
				</xsl:when>
			</xsl:choose>
			<xsl:copy-of select="legend"/>
		</xsl:element>
	</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="ipd2" userelativepaths="yes" externalpreview="no" url="..\..\FrameMaker\IPD\DMC&#x2D;S1000DBIKE&#x2D;AAA&#x2D;D00&#x2D;00&#x2D;00&#x2D;0000&#x2D;941A&#x2D;A_000&#x2D;02.XML" htmlbaseurl="" outputurl="..\..\FrameMaker\IPD\IPDtoFrame.xml" processortype="xalan" useresolver="yes" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator="" ><parameterValue name="mifpath" value="'C:\blah'"/></scenario></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="..\..\FrameMaker\IPD\DMC&#x2D;S1000DBIKE&#x2D;AAA&#x2D;D00&#x2D;00&#x2D;00&#x2D;0000&#x2D;941A&#x2D;A_000&#x2D;02.XML" srcSchemaRoot="dmodule" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition><template match="/"></template><template match="rdf:Description"></template><template match="dmodule[1]"></template></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->