<?xml version="1.0" encoding="iso-8859-1"?>

<!DOCTYPE xsl:stylesheet [
  <!ELEMENT Header (#PCDATA) >
  <!ENTITY tab "<xsl:text>&#9;</xsl:text>">
  <!ENTITY cr '<xsl:text xsl="http://www.w3.org/1999/XSL/Transform" space-"preserve">
</xsl:text>'>
]>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
  <xsl:output method="text" indent="yes" />
  <xsl:param name="te"/>  <!-- Brought in from PHP -->
  <xsl:variable name="decimals" select="'#.000'" /> <!-- Carry all values to 3 decimal places.  Change globally here -->

  <xsl:template match="/">
    <Header>TE Site&tab;Point&tab;Computed Latitude (DDMMSS.SSS H)&tab;Computed Longitude (DDDMMSS.SSS H)&tab;Computed Elevation HAE (m)&tab;CE90 (m)&tab;LE90 (m)&tab;Image IDs&cr;</Header>
    <xsl:apply-templates select="//event" />
  </xsl:template>
  

  <xsl:template match="event">
    
      <xsl:for-each select="point">
        <xsl:value-of select="$te"/>&tab;
		<xsl:value-of select="@id"/>&tab;
		<xsl:value-of select="@lat"/>&tab;
		<xsl:value-of select="@lon"/>&tab;
		<xsl:value-of select="format-number(@hae, $decimals)" />&tab;
        <xsl:value-of select="format-number(@ce, $decimals)" />&tab;
        <xsl:value-of select="format-number(@le, $decimals)" />&tab;
      </xsl:for-each>
         
      <xsl:for-each select="detail/image">
          <xsl:call-template name="substring-after-last" />
      </xsl:for-each>

			&cr;

  </xsl:template>
  

<!--
      Find the image name by recursively searching from the end of the string until a "\" is encountered
      This example was from Section 1.4 of XSLT Cookbook, although the book example would not work.
      The following changes were made:
          1. <xsl:param name="input"/> was changed to <xsl:param name="input" select="@url"/>
          2. <xsl:param name="substr"/> was deleted
          3. All references to $substr were deleted and replaced w/ &apos;\&apos;
          4. <xsl:with-param name="substr" select="$substr" /> was deleted
-->
  <xsl:template name="substring-after-last">
    <xsl:param name="input" select="@url"/>
    <!-- Extract the string, which comes after the first occurence -->
    <xsl:variable name="temp" select="substring-after($input, &apos;\&apos;)" />
    <xsl:choose>
    <!-- If it still contains the substring, then recursively process -->
      <xsl:when test="&apos;\&apos; and contains($temp, &apos;\&apos;)">
        <xsl:call-template name="substring-after-last">
          <xsl:with-param name="input" select="$temp" />
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$temp" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


	<!-- Display the DMS longitude -->
	<xsl:template name="output-lat">
	  <xsl:param name="deg"/>
		<xsl:param name="min"/>
		<xsl:param name="sec"/>
		<xsl:param name="hem"/>
		<xsl:value-of select="concat($deg,$min,$sec,$hem)"/>&tab;
	</xsl:template>

	<!-- Display the DMS longitude -->
	<xsl:template name="output-lon">
	  <xsl:param name="deg"/>
		<xsl:param name="min"/>
		<xsl:param name="sec"/>
		<xsl:param name="hem"/>
		<xsl:value-of select="concat($deg,$min,$sec,$hem)"/>&tab;
	</xsl:template>

</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="dpss_to_txt" userelativepaths="yes" externalpreview="no" url="dpss_logs\22AUG05_06240.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="yes" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->