<?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:inr="http://mycompany.com/mynamespace">
    <xsl:include href="../format.xsl"/>
    <xsl:param name="xslRootDirectory" select="inr:xslRootDirectory"/>
    <!-- Clearance Report -->
    <xsl:variable name="uniqueClearanceAlignments" select="//ClearancePoints/ClearancePoint[not(@clearanceAlignmentName = preceding-sibling::ClearancePoint/@clearanceAlignmentName )]/@clearanceAlignmentName "/>
    <xsl:output method="text" media-type="text/plain" encoding="iso-8859-1"/>
    <xsl:template match="/">
        <xsl:variable name="gridOut" select="inr:SetGridOut(number(InRoads/@outputGridScaleFactor))"/>
        <html>
            <head>
                <link rel="stylesheet" type="text/css" href="{$xslRootDirectory}/_Themes/engineer/theme.css"/>
                <!-- Title displayed in browser Title Bar -->
            </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">
                                <!-- Clearance Point Data -->
                                <xsl:for-each select="$uniqueClearanceAlignments">

                                            <xsl:for-each select="//ClearancePoint[@clearanceAlignmentName = current()]">
                                                <tr>
						<xsl:variable name="PointName" select="offsetPoint/@name"/>
						<xsl:if test="$PointName">
                                                    <td align="right">
                                                        <xsl:value-of select="inr:columnFormat(string(offsetPoint/@name),5)"/>
                                                    </td>
                                                    <td align="right">
                                                        <xsl:value-of select="inr:columnFormat(inr:stationFormat(number(centerLinePoint/point/station/@externalStation), $xslStationFormat, $xslStationPrecision, string(centerLinePoint/point/station/@externalStationName)),14)"/>
                                                    </td>
                                                    <td align="right">
                                                        <xsl:value-of select="inr:columnFormat(inr:distanceFormat(number(@firstOffset), $xslDistancePrecision),10)"/>
                                                    </td>
                                                    <td align="right">
                                                        <xsl:value-of select="inr:columnFormat(inr:northingFormat(number(offsetPoint/@northing), $xslNorthingPrecision),13)"/>
                                                    </td>
                                                    <td align="right">
                                                        <xsl:value-of select="inr:columnFormat(inr:eastingFormat(number(offsetPoint/@easting), $xslEastingPrecision),12)"/>
                                                    </td>
                                                    <td align="right">
                                                        <xsl:value-of select="inr:columnFormat(inr:elevationFormat(number(offsetPoint/@elevation), $xslElevationPrecision),10)"/><xsl:text>&#xd;</xsl:text>
                                                    </td>
						</xsl:if>
                                                </tr>
                                            </xsl:for-each>


                                </xsl:for-each>
                                <!-- Clearance Points from Cogo Data -->
                                <xsl:if test="//ClearancePoint[@origin = 'point']">
                                    <xsl:for-each select="//ClearancePoints">
                                        <table class="margin" cellpadding="10">
                                            <tbody>
                                                <xsl:for-each select="//ClearancePoint[@origin = 'point']">
                                                    <tr>
                                                        <td align="right">
                                                        <xsl:value-of select="inr:columnFormat(string(offsetPoint/@name),5)"/>
                                                    </td>
                                                    <td align="right">
                                                        <xsl:value-of select="inr:columnFormat(inr:stationFormat(number(centerLinePoint/point/station/@externalStation), $xslStationFormat, $xslStationPrecision, string(centerLinePoint/point/station/@externalStationName)),14)"/>
                                                    </td>
                                                    <td align="right">
                                                        <xsl:value-of select="inr:columnFormat(inr:distanceFormat(number(@firstOffset), $xslDistancePrecision),10)"/>
                                                    </td>
                                                    <td align="right">
                                                        <xsl:value-of select="inr:columnFormat(inr:northingFormat(number(offsetPoint/@northing), $xslNorthingPrecision),13)"/>
                                                    </td>
                                                    <td align="right">
                                                        <xsl:value-of select="inr:columnFormat(inr:eastingFormat(number(offsetPoint/@easting), $xslEastingPrecision),12)"/>
                                                    </td>
                                                    <td align="right">
                                                        <xsl:value-of select="inr:columnFormat(inr:elevationFormat(number(offsetPoint/@elevation), $xslElevationPrecision),10)"/><xsl:text>&#xd;</xsl:text>
                                                    </td>
                                                    </tr>
                                                </xsl:for-each>
                                            </tbody>
                                        </table>
                                    </xsl:for-each>
                                </xsl:if>
                            </xsl:for-each>
                        </xsl:for-each>
                    </xsl:otherwise>
                </xsl:choose>
            </body>
        </html>
    </xsl:template>
    <xsl:template name="StyleSheetHelp">
        <div class="section1">
            <h4 lang="en">Notes</h4>
            <p class="normal1" lang="en">
                You must create clearance points for this report by selecting <em>Tools &gt; XML Reports 
                &gt; Clearance</em>.
            </p>
            <p class="normal1" lang="en">
                You must include at least one horizontal alignment or feature on the <em>General</em> leaf 
                in the <em>From</em> fields.
            </p>
            <p class="normal1" lang="en">
                You must also include at least one horizontal alignment on the <em>Horizontal Alignments
                </em> leaf or one cogo point on the <em>Cogo Points</em> leaf or one feature on the <em>
                Features</em> leaf.
            </p>
            <p class="small" lang="en">
                <em>&#xa9; 2006 Bentley Systems, Inc</em>
            </p>
        </div>
    </xsl:template>
</xsl:stylesheet>
