<?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:text>PointName,Northing,Easting,Elevation,Code&#xd;</xsl:text>
            <xsl:apply-templates/>
        </xsl:for-each>
    </xsl:template>

    <xsl:template match="GeometryPoint">
        <xsl:for-each select="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="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: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>
