<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tps="http://www.typefi.com/ContentXML">

	<!-- Change Styles in "Single Page Sight" context 05/26/09-->
	<xsl:template match="tps:context[@type='Single Page Sight']">
		<xsl:element name="tps:context">
			<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
			<xsl:attribute name="type"><xsl:value-of select="@type"/>
			</xsl:attribute>
		
		<xsl:choose>
		<xsl:when test="count(tps:p[@type='tx1'])=1">
		<xsl:if test="//tps:image[following-sibling::tps:c/@type='property name']">
			<xsl:element name="tps:p">
				<xsl:attribute name="type">bh - 2 col</xsl:attribute>
				<xsl:element name="tps:image">
					<xsl:attribute name="ref"><xsl:value-of select="tps:p[@type='tx1']/tps:image/@ref"/>
				</xsl:attribute>
					<xsl:attribute name="comment"><xsl:value-of select="tps:p[@type='tx1']/tps:image/@comment"/>
				</xsl:attribute>
				</xsl:element>
				<xsl:choose>
				<xsl:when test="ends-with(normalize-space(tps:p[@type='tx1']/tps:c[@type='property name']/text()), '.')">
					<xsl:value-of select="substring-before(normalize-space(tps:p[@type='tx1']/tps:c[@type='property name']/text()), '.')"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="tps:p[@type='tx1']/tps:c[@type='property name']/text()"/>&#x0D;
				</xsl:otherwise>
				</xsl:choose>
			</xsl:element>
		</xsl:if>  

		<xsl:if test="tps:p[@type='tx1']/text()[name(preceding-sibling::tps:c[1]) and preceding-sibling::tps:c[1]/@type='property name']">
			<xsl:element name="tps:p">
				<xsl:attribute name="type">tx2 - txt in 2 col</xsl:attribute>
				<xsl:choose>
					<xsl:when test="tps:p[@type='tx1']/text()[substring(normalize-space(.),1,1) = '.'][name(preceding-sibling::tps:c[1]) and preceding-sibling::tps:c[1]/@type='property name']">
						<xsl:value-of select="substring-after(normalize-space(tps:p[@type='tx1']/text()[name(preceding-sibling::tps:c[1]) and preceding-sibling::tps:c[1]/@type='property name']), '.')"/>
					</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="tps:p[@type='tx1']/text()[name(preceding-sibling::tps:c[1]) and preceding-sibling::tps:c[1]/@type='property name']"/>
				</xsl:otherwise>
				</xsl:choose>
				<xsl:element name="tps:s">
				</xsl:element>&#x20;		<!--space-->
				<xsl:if test="tps:p[@type='tx1']/text()[name(preceding-sibling::tps:c[1]) and preceding-sibling::tps:c[1]/@type='property name'][following-sibling::tps:c/@type='Semi-bold']">
					<xsl:copy-of select="tps:p[@type='tx1']/tps:c[@type='Semi-bold'][1]"/>
					<xsl:choose>
					<xsl:when test="count(tps:p[@type='tx1']/tps:c[@type='Tip'] | tps:p[@type='tx1']/tps:c[@type='Tips'])=1">
						<xsl:apply-templates select="tps:p[@type='tx1']/node()[preceding-sibling::tps:c/@type='Semi-bold' and following-sibling::tps:c[@type='Tip'][not(self::type='Tip')]]">
						</xsl:apply-templates>11111
					</xsl:when>
					<xsl:otherwise>
						<!--<xsl:for-each select="tps:p[@type='tx1']/tps:c[@type='Tip'] | tps:c[@type='Tips']">
							<xsl:choose>
								<xsl:when test="position() = 1">-->
									<xsl:apply-templates select="tps:p[@type='tx1']/node()[preceding-sibling::tps:c/@type='Semi-bold' and following-sibling::tps:c[@type='Tip']/text()]">
									</xsl:apply-templates>22222--How can I get rid of above extra 'Tip' line?
								<!--</xsl:when>
								<xsl:otherwise>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:for-each>-->
					</xsl:otherwise>
					</xsl:choose>
				</xsl:if>			
			</xsl:element>
		</xsl:if>

		<xsl:for-each select="tps:p[@type='tx1']/tps:c[@type='Tip']|tps:p[@type='tx1']/tps:c[@type='Tips']">
			<xsl:choose>
				<xsl:when test="position() = 1">
					<xsl:element name="tps:p">
						<xsl:attribute name="type">mm - h2  narrow</xsl:attribute>Tips
					</xsl:element>
				</xsl:when>
				<xsl:otherwise>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:element name="tps:p">
				<xsl:attribute name="type">btx - bulleted box text</xsl:attribute>
				<xsl:value-of select="text()"/>
				<xsl:element name="tps:s">
				</xsl:element>
			</xsl:element>
		</xsl:for-each>

		<xsl:if test="tps:p[@type='tx1']/tps:c[@type='HM Char - hidden meta']/substring(normalize-space(text()),2,2) = 'SI'">
			<xsl:element name="tps:p">
				<xsl:attribute name="type">mm - si</xsl:attribute>
				<xsl:apply-templates select="tps:p[@type='tx1']/node()[preceding-sibling::tps:c[@type='HM Char - hidden meta']/substring(text(),2,2) ='SI']">
				</xsl:apply-templates>
			</xsl:element>
		</xsl:if>
	</xsl:when>
	<xsl:otherwise>		<!--more than one p[@type='tx1']-->
		<xsl:for-each select="tps:p[@type='tx1']">
		<xsl:choose>
		<xsl:when test="(position() = 1) and (tps:image[following-sibling::tps:c/@type='property name'])">
			<xsl:element name="tps:p">
				<xsl:attribute name="type">bh - 2 col</xsl:attribute>
				<xsl:element name="tps:image">
					<xsl:attribute name="ref"><xsl:value-of select="tps:image/@ref"/>
				</xsl:attribute>
					<xsl:attribute name="comment"><xsl:value-of select="tps:image/@comment"/>
				</xsl:attribute>
				</xsl:element>
				<xsl:choose>
				<xsl:when test="ends-with(normalize-space(tps:c[@type='property name']/text()), '.')">
					<xsl:value-of select="substring-before(normalize-space(tps:c[@type='property name']/text()), '.')"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="tps:c[@type='property name']/text()"/>
				</xsl:otherwise>
				</xsl:choose>
			</xsl:element>
			<xsl:if test="text()[name(preceding-sibling::tps:c[1]) and preceding-sibling::tps:c[1]/@type='property name']">
				<xsl:element name="tps:p">
					<xsl:attribute name="type">tx2 - txt in 2 col</xsl:attribute>
					<xsl:choose>
						<xsl:when test="text()[substring(normalize-space(.),1,1) = '.'][name(preceding-sibling::tps:c[1]) and preceding-sibling::tps:c[1]/@type='property name']">
							<xsl:value-of select="substring-after(normalize-space(text()[name(preceding-sibling::tps:c[1]) and preceding-sibling::tps:c[1]/@type='property name']), '.')"/>
						</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="text()[name(preceding-sibling::tps:c[1]) and preceding-sibling::tps:c[1]/@type='property name']"/>
					</xsl:otherwise>
					</xsl:choose>
					<xsl:element name="tps:s">
					</xsl:element>
				</xsl:element>
			</xsl:if>
		</xsl:when> 
		<xsl:otherwise>
			<xsl:element name="tps:p">
				<xsl:attribute name="type">tx2 - txt in 2 col</xsl:attribute>
				<xsl:value-of select="text()[1]"/>
				<xsl:element name="tps:s">
				</xsl:element>
				<xsl:if test="text()[name(following-sibling::tps:c[1]) and following-sibling::tps:c[1][@type='Semi-bold']]">
					<xsl:copy-of select="tps:c[@type='Semi-bold'][1]"/>
					<xsl:apply-templates select="node()[preceding-sibling::tps:c[1][@type='Semi-bold'] and following-sibling::tps:c[@type='Tip']]">
					</xsl:apply-templates>
				</xsl:if>
			</xsl:element>
		</xsl:otherwise>
		</xsl:choose>
	</xsl:for-each> 

	<xsl:for-each select="tps:p[@type='tx1']/tps:c[@type='Tip']|tps:p[@type='tx1']/tps:c[@type='Tips']">
		<xsl:choose>
			<xsl:when test="position() = 1">
				<xsl:element name="tps:p">
					<xsl:attribute name="type">mm - h2  narrow</xsl:attribute>Tips
				</xsl:element>
			</xsl:when>
			<xsl:otherwise>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:element name="tps:p">
			<xsl:attribute name="type">btx - bulleted box text</xsl:attribute>
			<xsl:value-of select="text()"/>
			<xsl:element name="tps:s">
			</xsl:element>
		</xsl:element>
	</xsl:for-each>

	<xsl:if test="tps:p[@type='tx1']/tps:c[@type='HM Char - hidden meta']/substring(normalize-space(text()),2,2) = 'SI'">
		<xsl:element name="tps:p">
			<xsl:attribute name="type">mm - si</xsl:attribute>
			<xsl:apply-templates select="tps:p[@type='tx1']/node()[preceding-sibling::tps:c[@type='HM Char - hidden meta']/substring(text(),2,2) ='SI']">
			</xsl:apply-templates>
		</xsl:element>
	</xsl:if>
	</xsl:otherwise>
	</xsl:choose>
	</xsl:element>
	</xsl:template>

	<!-- Put Hidden Meta Data in to a HMD Element -->
	<xsl:template match="tps:p[@type='HM - hidden meta']|
	                     tps:p[@type='HM - hidden meta START']|
						 tps:p[@type='HM - hidden meta END']">
	</xsl:template>

	<xsl:template match="tps:c[@type='HM Char - hidden meta']|
	                     tps:c[@type='HM Char - hidden meta START']|
						 tps:c[@type='HM Char - hidden meta END']">
	</xsl:template>


	

	<!-- Copy the rest of the content and nodes -->
	<xsl:template match="node()|@*">
 		<xsl:copy>
			<xsl:apply-templates select="@*|node()"/>
		</xsl:copy>
	</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2007. Progress Software Corporation. All rights reserved.

<metaInformation>
	<scenarios>
		<scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="tips.xml" htmlbaseurl="" outputurl="" processortype="saxon8" useresolver="yes" profilemode="0" profiledepth="" profilelength="" urlprofilexml=""
		          commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator="">
			<advancedProp name="sInitialMode" value=""/>
			<advancedProp name="bXsltOneIsOkay" value="true"/>
			<advancedProp name="bSchemaAware" value="true"/>
			<advancedProp name="bXml11" value="false"/>
			<advancedProp name="iValidation" value="0"/>
			<advancedProp name="bExtensions" value="true"/>
			<advancedProp name="iWhitespace" value="0"/>
			<advancedProp name="sInitialTemplate" value=""/>
			<advancedProp name="bTinyTree" value="true"/>
			<advancedProp name="bWarnings" value="true"/>
			<advancedProp name="bUseDTD" value="false"/>
			<advancedProp name="iErrorHandling" value="0"/>
		</scenario>
	</scenarios>
	<MapperMetaTag>
		<MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
		<MapperBlockPosition></MapperBlockPosition>
		<TemplateContext></TemplateContext>
		<MapperFilter side="source"></MapperFilter>
	</MapperMetaTag>
</metaInformation>
-->