<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:cif="cif">
    <xsl:param name="xslShowHelp" select="cif:xslShowHelp"/>
    <xsl:param name="xslRootDirectory" select="cif:xslRootDirectory"/>
    
    <!-- Variable to hold unit string -->
    <xsl:variable name="unit">
        <xsl:choose>
            <xsl:when test="//@linearUnits = 'Imperial'"> feet</xsl:when>
            <xsl:otherwise> meters</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    
    <!-- Horizontal Alignment Legal Description -->
    <xsl:template match="/">
        <xsl:variable name="gridOut" select="cif:SetGridOut(number(InRoads/@outputGridScaleFactor))"/>
        <html lang="en">
            <head>
                <link rel="stylesheet" type="text/css" href="{$xslRootDirectory}/_Themes/engineer/theme.css"/>
								<style type="text/css">body{font-family:"Cambria";font-size:"12pt"}</style>
                <!-- Title displayed in browser Title Bar -->
                <title>Property Description</title>
            </head>
            
            <body>
                <xsl:choose>
                    <xsl:when test="$xslShowHelp = 'true'">
                        <xsl:call-template name="StyleSheetHelp"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:for-each select="InRoads">
                            				
                            <!-- Project Data -->
                            <xsl:for-each select="GeometryProject">
                                <!-- Horizontal Alignment Data -->
                                <div style="margin-left:0in;margin-right:0in">
                                    <xsl:for-each select="HorizontalAlignment">                        
																				<center>
                                					<!-- Report Title -->
                                					<h2>Metes and Bounds Report</h2>
                                					<p lang="en">
                                    					<b>PARCEL:&#xa0; <xsl:value-of select="@name"/></b><br/><br/>
                                    					Report Created:&#xa0; <xsl:value-of select="cif:date()"/><br/>
                                    					Time:&#xa0; <xsl:value-of select="cif:time()"/>
                                					</p>
                            						</center>
                            						
																				<hr/><br/>
                                        																				
                                        <xsl:apply-templates select="//HorizontalLine | //HorizontalCircle | //HorizontalSpiral"/>
																				
                                        <xsl:if test="@area > 0">
                                            <!--The above described parcel contains -->
                                            <xsl:if test="//@linearUnits = 'Imperial'">
                                                <xsl:value-of select="cif:acreFormat(number(@area) div 43560)"/> acres,
																								more or less of which the present road occupies [#.###] acres, resulting in a net take of [#.###] acres.
                                                <!--(<xsl:value-of select="cif:areaFormat(number(@area))"/> sq. ft.)-->
                                            </xsl:if>

                                            <xsl:if test="//@linearUnits = 'Metric'">
                                                <xsl:value-of select="cif:acreFormat(number(@area) div 10000)"/> hectares,
																								more or less of which the present road occupies [#.####] hectares, resulting in a net take of [#.###] hectares.
                                                <!-->(<xsl:value-of select="cif:areaFormat(number(@area))"/> sq. m.)-->
                                            </xsl:if>

                                        </xsl:if>
                                        <br/>
                                    </xsl:for-each>
                                </div>
                            </xsl:for-each>
                        </xsl:for-each>
                    </xsl:otherwise>
                </xsl:choose>
            </body>
        </html>
    </xsl:template>


    <!-- Horizontal Line -->
    <xsl:template match="HorizontalLine">
        <xsl:choose>
            <xsl:when test="position() = 1">
                <!-- ... to -->
               <xsl:if test="Start/legalReference">
                    <xsl:if test="Start/legalReference/@offset >= 0">
                        <xsl:value-of select="cif:distanceFormat(number(Start/legalReference/@offset))"/>
                    </xsl:if>
                    <xsl:if test="Start/legalReference/@offset &lt; 0">
                        <xsl:value-of select="cif:distanceFormat(number(0 - Start/legalReference/@offset))"/>
                    </xsl:if>
                    <b><xsl:value-of select="$unit"/></b>. 
                    <xsl:if test="Start/legalReference/@offset >= 0"> right </xsl:if>
                    <xsl:if test="Start/legalReference/@offset &lt; 0"> left </xsl:if>
                    of Station					         
                    <xsl:value-of select="cif:stationFormat(number(Start/legalReference/station/@externalStation), string(Start/legalReference/station/@externalStationName))"/>
										of the <xsl:value-of select="Start/legalReference/@referenceAlignment"/>,  
										said point marking the Principle Point of Beginning.
										<br/><br/>
               </xsl:if>
		
								<!-- <xsl:value-of select="@elementNumber"/>. --> 
                Thence
                <b><xsl:value-of select="cif:directionFormat(number(@direction))"/></b>
                along [DESCRIBE LINE], a distance of				
                <b><xsl:value-of select="cif:distanceFormat(number(@length))"/></b>
                <b><xsl:value-of select="$unit"/></b> ;
		
                <xsl:if test="End/legalReference">
                    to [DESCRIBE MONUMENT], said monument being 
                    <xsl:if test="End/legalReference/@offset >= 0">
                        <b><xsl:value-of select="cif:distanceFormat(number(End/legalReference/@offset))"/></b>
                    </xsl:if>
                    <xsl:if test="End/legalReference/@offset &lt; 0">
                        <b><xsl:value-of select="cif:distanceFormat(number(0 - End/legalReference/@offset))"/></b>
                    </xsl:if>
                    <b><xsl:value-of select="$unit"/></b>
			
                    <xsl:if test="End/legalReference/@offset >= 0"> right </xsl:if>
                    <xsl:if test="End/legalReference/@offset &lt; 0"> left </xsl:if>
                    of Station 
                    <xsl:value-of select="cif:stationFormat(number(End/legalReference/station/@externalStation), string(End/legalReference/station/@externalStationName))"/>
										of the <xsl:value-of select="End/legalReference/@referenceAlignment"/>;<br/><br/>
		    				</xsl:if>
						</xsl:when>

            <xsl:when test="position() = last()">
								<!-- <xsl:value-of select="@elementNumber"/>. -->
                <p/>Thence <b><xsl:value-of select="cif:directionFormat(number(@direction))"/></b>
                along [DESCRIBE LINE], a distance of
                <b><xsl:value-of select="cif:distanceFormat(number(@length))"/></b>
                <b><xsl:value-of select="$unit"/></b>
                to the Principle Point of Beginning and enclosing               
            </xsl:when>
								
            <xsl:otherwise>			
								<!-- <xsl:value-of select="@elementNumber"/>. -->
                <p/>Thence <b><xsl:value-of select="cif:directionFormat(number(@direction))"/></b>
                along [DESCRIBE LINE], a distance of
                <b><xsl:value-of select="cif:distanceFormat(number(@length))"/></b>
                <b><xsl:value-of select="$unit"/></b> ;
		
                <xsl:if test="End/legalReference">
                    to [DESCRIBE MONUMENT], said monument being 
                    <xsl:if test="End/legalReference/@offset >= 0">
                    		<b><xsl:value-of select="cif:distanceFormat(number(End/legalReference/@offset))"/></b>
                    </xsl:if>
                    <xsl:if test="End/legalReference/@offset &lt; 0">
                        <b><xsl:value-of select="cif:distanceFormat(number(0 - End/legalReference/@offset))"/></b>
                    </xsl:if>
                    <b><xsl:value-of select="$unit"/></b>
                    <xsl:if test="End/legalReference/@offset >= 0"> right </xsl:if>
                    <xsl:if test="End/legalReference/@offset &lt; 0"> left </xsl:if>
                    of Station 
                    <xsl:value-of select="cif:stationFormat(number(End/legalReference/station/@externalStation), string(End/legalReference/station/@externalStationName))"/>
		    						of the <xsl:value-of select="End/legalReference/@referenceAlignment"/>;<br/><br/>
                </xsl:if>						
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>


    <!-- Horizontal Circle -->
    <xsl:template match="HorizontalCircle">
        <xsl:choose>
            <xsl:when test="position() = 1">			
                ... to 
                <xsl:if test="Start/legalReference">
                    <xsl:if test="Start/legalReference/@offset >= 0">
                        <xsl:value-of select="cif:distanceFormat(number(Start/legalReference/@offset))"/>
                    </xsl:if>
                    <xsl:if test="Start/legalReference/@offset &lt; 0">
                        <xsl:value-of select="cif:distanceFormat(number(0 - Start/legalReference/@offset))"/>
                    </xsl:if>
                    <xsl:value-of select="$unit"/>
                    <xsl:if test="Start/legalReference/@offset >= 0"> right </xsl:if>
                    <xsl:if test="Start/legalReference/@offset &lt; 0"> left </xsl:if>
                    of Station
                    <xsl:value-of select="cif:stationFormat(number(Start/legalReference/station/@externalStation), string(Start/legalReference/station/@externalStationName))"/>
										of the <xsl:value-of select="Start/legalReference/@referenceAlignment"/>
										said point marking the Principle Point of Beginning.<br/><br/>
                </xsl:if>
									<!-- <xsl:value-of select="@elementNumber"/>. -->
                <p/>Thence, along [DESCRIBE LINE] with a curve 
								<xsl:if test="@rotationDirection = 'cw'"> to the right, </xsl:if>
                	<xsl:if test="@rotationDirection = 'ccw'"> to the left, </xsl:if>
               		having a radius of
                	<xsl:value-of select="cif:distanceFormat(number(@radius))"/>
                	<xsl:value-of select="$unit"/>, 
									a central angle of 
									<xsl:value-of select="cif:angularFormat(number(@delta))"/>,     
									and an arc length of
									<xsl:value-of select="cif:distanceFormat(number(@length))"/>
                	<xsl:value-of select="$unit"/>,
                	said curve has a chord which bears
                	<b><xsl:value-of select="cif:directionFormat(number(@chordDirection))"/></b>
                	and has a distance of
                	<b><xsl:value-of select="cif:distanceFormat(number(@chord))"/>
                	<xsl:value-of select="$unit"/></b>,
                	<xsl:if test="End/legalReference">
                    to [DESCRIBE MONUMENT], said monument being
                    <xsl:if test="End/legalReference/@offset >= 0">
                        <xsl:value-of select="cif:distanceFormat(number(End/legalReference/@offset))"/>
                    </xsl:if>
                    <xsl:if test="End/legalReference/@offset &lt; 0">
                        <xsl:value-of select="cif:distanceFormat(number(0 - End/legalReference/@offset))"/>
                    </xsl:if>
                    <xsl:value-of select="$unit"/>
                    <xsl:if test="End/legalReference/@offset >= 0"> right </xsl:if>
                    <xsl:if test="End/legalReference/@offset &lt; 0"> left </xsl:if>
                    of Station 
                    of the <xsl:value-of select="cif:stationFormat(number(End/legalReference/station/@externalStation), string(End/legalReference/station/@externalStationName))"/>
		    						<xsl:value-of select="End/legalReference/@referenceAlignment"/>;<br/><br/>
                </xsl:if>												                                         
            </xsl:when>
            <xsl:when test="position() = last()">					
								<!-- <xsl:value-of select="@elementNumber"/>. -->
                <p/>Thence, along [DESCRIBE LINE] with a curve                 
                <xsl:if test="@rotationDirection = 'cw'"> to the right, </xsl:if>
                <xsl:if test="@rotationDirection = 'ccw'"> to the left, </xsl:if>
                having a radius of
                <xsl:value-of select="cif:distanceFormat(number(@radius))"/>
                <xsl:value-of select="$unit"/>,
									a central angle of 
									<xsl:value-of select="cif:angularFormat(number(@delta))"/>,
									and an arc length of
									<xsl:value-of select="cif:distanceFormat(number(@length))"/>
                <xsl:value-of select="$unit"/>,
                said curve has a chord which bears
                <b><xsl:value-of select="cif:directionFormat(number(@chordDirection))"/></b>
                and has a distance of
                <b><xsl:value-of select="cif:distanceFormat(number(@chord))"/>
                <xsl:value-of select="$unit"/></b>,
                to the Principle Point of Beginning and enclosing 						                             
            </xsl:when>
            <xsl:otherwise>			
               <p/>Thence, along [DESCRIBE LINE] with a curve            
                <xsl:if test="@rotationDirection = 'cw'"> to the right, </xsl:if>
                <xsl:if test="@rotationDirection = 'ccw'"> to the left, </xsl:if>
                having a radius of
                <xsl:value-of select="cif:distanceFormat(number(@radius))"/>
                <xsl:value-of select="$unit"/>,
                a central angle of 
				<xsl:value-of select="cif:angularFormat(number(@delta))"/>,
				and an arc length of
				<xsl:value-of select="cif:distanceFormat(number(@length))"/>
                <xsl:value-of select="$unit"/>,
                said curve has a chord which bears
                <b><xsl:value-of select="cif:directionFormat(number(@chordDirection))"/></b>
                and has a distance of
                <b><xsl:value-of select="cif:distanceFormat(number(@chord))"/>
                <xsl:value-of select="$unit"/></b>,
								to [DESCRIBE MONUMENT], said monument being 
                <xsl:if test="End/legalReference/@offset >= 0">
		    				<xsl:value-of select="cif:distanceFormat(number(End/legalReference/@offset))"/>
                </xsl:if>
                <xsl:if test="End/legalReference/@offset &lt; 0">
                    <xsl:value-of select="cif:distanceFormat(number(0 - End/legalReference/@offset))"/>
                </xsl:if>
                <xsl:value-of select="$unit"/>
                <xsl:if test="End/legalReference/@offset >= 0"> right </xsl:if>
                <xsl:if test="End/legalReference/@offset &lt; 0"> left </xsl:if>
                of Station
                <xsl:value-of select="cif:stationFormat(number(End/legalReference/station/@externalStation), string(End/legalReference/station/@externalStationName))"/>
								of the <xsl:value-of select="End/legalReference/@referenceAlignment"/>;<br/><br/>    									                
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>


    <!-- Horizontal Spiral -->
    <xsl:template match="HorizontalSpiral">
        <xsl:choose>
            <xsl:when test="position() = 1">
                Thence at
                <xsl:choose>
                    <xsl:when test="Start/@name">
                        <xsl:value-of select="Start/@name"/>,<br/>
                    </xsl:when>
                    <xsl:otherwise>
                        a point,<br/>
                    </xsl:otherwise>
                </xsl:choose>
                said point being POINT OF BEGINNING;<br/>
                to a point on a spiral
                <xsl:choose>
                    <xsl:when test="End/@name">
                        <xsl:value-of select="End/@name"/>,<br/>
                    </xsl:when>
                    <xsl:otherwise><br/></xsl:otherwise>
                </xsl:choose>
                the chord of which is
                <b><xsl:value-of select="cif:directionFormat(number(@chordDirection))"/></b>,
                for a distance of
                <b><xsl:value-of select="cif:distanceFormat(number(@longChord))"/>
                <xsl:value-of select="$unit"/></b>,<br/>
            </xsl:when>
            <xsl:when test="position() = last()">
                to a point on a spiral
                <xsl:choose>
                    <xsl:when test="End/@name">
                        <xsl:value-of select="End/@name"/>,<br/>
                    </xsl:when>
                    <xsl:otherwise><br/></xsl:otherwise>
                </xsl:choose>
                the chord of which is
                <b><xsl:value-of select="cif:directionFormat(number(@chordDirection))"/></b>,
                for a distance of
                <b><xsl:value-of select="cif:distanceFormat(number(@longChord))"/>
                <xsl:value-of select="$unit"/></b>.<br/>
            </xsl:when>
            <xsl:otherwise>
                to a point on a spiral
                <xsl:choose>
                    <xsl:when test="End/@name">
                        <xsl:value-of select="End/@name"/>,<br/>
                    </xsl:when>
                    <xsl:otherwise><br/></xsl:otherwise>
                </xsl:choose>
                the chord of which is
                <b>xsl:value-of select="cif:directionFormat(number(@chordDirection))"/></b>,
                for a distance of
                <b><xsl:value-of select="cif:distanceFormat(number(@longChord))"/>
                <xsl:value-of select="$unit"/></b>,<br/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="StyleSheetHelp">
        <div class="section1">
            <h4 lang="en">Notes</h4>
            <p class="normal1" lang="en">
                You must include at least one horizontal alignment in the <em>Include</em> field on the 
                <em>Tools &gt; XML Reports &gt; Legal Description</em> or the <em>Tools &gt; XML Reports 
                &gt; Geometry</em> command to get results from this report.
            </p>
            <p class="normal1" lang="en">
                This report is not suitable for a reference alignment.
            </p>
            <p class="small" lang="en">
                <em>&#xa9; 2006 Bentley Systems, Inc</em>
            </p>
        </div>
    </xsl:template>
</xsl:stylesheet>
