<?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:strip-space elements="*"/>
    <xsl:output method="text" media-type="text/plain" encoding="iso-8859-1"/>
    
    <xsl:template match="/">
        <xsl:variable name="gridOut" select="cif:SetGridOut(number(InRoads/@outputGridScaleFactor))"/> 
        <xsl:for-each select="InRoads/GeometryProject">
        	<xsl:variable name="HA_Name" select="HorizontalAlignment/@name"/>
        	<xsl:text>PointName,Alignment,Station,Offset,Northing,Easting,Elevation,Code&#xd;</xsl:text>
		
		<xsl:for-each select="HorizontalAlignment[OffsetPoint]">
			<xsl:for-each select="OffsetPoint/GeometryPointProperties">
			
			<xsl:variable name="fullFeatureName" select="@FeatureName" />
			<xsl:variable name="items">
			<xsl:call-template name="splitStringToItems">
			  <xsl:with-param name="list" select="$fullFeatureName" />
			</xsl:call-template>
			</xsl:variable>

				<xsl:value-of select="@PointName"/>,<xsl:value-of select="$HA_Name"/>,<xsl:value-of select="cif:stationFormat(number(station/@externalStation),string(station/@externalStationName))"/>,<xsl:value-of select="cif:distanceFormat(number(@offset))"/>,<xsl:value-of select="cif:ordinateFormat(number(@northing))"/>,<xsl:value-of select="cif:ordinateFormat(number(@easting))"/>,<xsl:value-of select="cif:ordinateFormat(number(@elevation))"/>,<xsl:value-of select="msxsl:node-set($items)/item[last()]"/><xsl:text>&#xd;</xsl:text>

			</xsl:for-each>
		</xsl:for-each>
		
	</xsl:for-each>
    </xsl:template>


<xsl:template name="StyleSheetHelp">
  <p class="normal1" lang="en">
    This report has no additional notes.
  </p>
</xsl:template>

<xsl:template name="splitStringToItems">
      <xsl:param name="list" />
      <xsl:variable name="delimiter" select="'\'">
      </xsl:variable>
      <xsl:variable name="newlist">
        <xsl:choose>
          <xsl:when test="contains($list, $delimiter)">
            <xsl:value-of select="normalize-space($list)" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="concat(normalize-space($list), $delimiter)"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:variable name="firstString" select="substring-before($newlist, $delimiter)" />
      <xsl:variable name="remainingString" select="substring-after($newlist, $delimiter)" />
      <item>
        <xsl:value-of select="$firstString" />
      </item>
      <xsl:if test="$remainingString">
        <xsl:call-template name="splitStringToItems">
          <xsl:with-param name="list" select="$remainingString" />
          <xsl:with-param name="delimiter" select="$delimiter" />
        </xsl:call-template>
      </xsl:if>
</xsl:template>

</xsl:stylesheet>
