<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:js="JavaScript">
 <msxsl:script language="JavaScript" implements-prefix="js"><![CDATA[
function UpperCase(Value)
{
return Value.toUpperCase();
}
 
function LowerCase(Value)
{
return Value.toLowerCase();
}

function Conversione(time)
{
//minuti
var foobar=time % (60); 
// ore
var minutes = Math.floor(time / 60); 

var zero = "";
if (minutes < 10)
{
zero = "0"
}


var foo = "";
if (foobar < 10)
{
foo = "0"
}

var oraok="h "+ zero+minutes+" m "+foo+foobar ;
return (oraok);
}


]]>
 </msxsl:script>

 <xsl:output method="html" indent="yes"/>
 <xsl:param name="recordsPerPage" select="1"/>
 <xsl:param name="pageNumber"/>
 <xsl:param name="route"/>
 <xsl:param name="attempt" select="2"/>
 <xsl:param name="routingid"/>
 <xsl:param name="loginid"/>
 <xsl:param name="dataok1"/>
 <xsl:param name="dataok2"/>


 <xsl:template match="/">
  <xsl:variable name="eur_currency" select="number(document('valute1.xml')/CommandList/GetCurrencies/CurrencyList/Currency/Code[. ='EUR']/following-sibling::UsdRate[1])"/>
  
  <xsl:variable name="base">
  <xsl:for-each select="/CommandList/CheckRouting/RouterList/Router[Complete='true']/GroupList/Group">
   <xsl:variable name="pos_start" select="position()"></xsl:variable>
   <xsl:variable name="supplier" select="../../Supplier"></xsl:variable>

   <xsl:variable name="prezzo_gruppo" select="Price/Amount"/>
   <xsl:variable name="valuta_gruppo" select="Price/Currency"/>
   <xsl:variable name="valore_gruppo" select="number(document('valute1.xml')/CommandList/GetCurrencies/CurrencyList/Currency/Code[. =$valuta_gruppo]/following-sibling::UsdRate[1])"/>
   <xsl:variable name="prezzo_unico" select="format-number((($prezzo_gruppo) div ($valore_gruppo)) * $eur_currency,'#.##')"/>

   <xsl:for-each select="OutwardList/Outward">
    <xsl:variable name="pos" select="position()"/>
    <xsl:for-each select="../../ReturnList/Return">
     <xsl:variable name="posrt" select="position()"/>
     <xsl:variable name="valuta_ow" select="../../OutwardList/Outward[$pos]/Price/Currency"/>
     <xsl:variable name="valore_ow" select="number(document('valute1.xml')/CommandList/GetCurrencies/CurrencyList/Currency/Code[. =$valuta_ow]/following-sibling::UsdRate[1])"/>
     <xsl:variable name="valuta_rt" select="../../ReturnList/Return[$posrt]/Price/Currency"/>
     <xsl:variable name="valore_rt" select="number(document('valute1.xml')/CommandList/GetCurrencies/CurrencyList/Currency/Code[.=$valuta_rt]/following-sibling::UsdRate[1])"/>
     <xsl:variable name="valuta_un" select="../../ReturnList/Return[$posrt]/Price/Currency"/>
     <xsl:variable name="valore_un" select="number(document('valute1.xml')/CommandList/GetCurrencies/CurrencyList/Currency/Code[.=$valuta_rt]/following-sibling::UsdRate[1])"/>
     <xsl:variable name="prezzo_ow" select="format-number(((../../OutwardList/Outward[$pos]/Price/Amount) div ($valore_ow)) * ($eur_currency),'#.##')"/>
     <xsl:variable name="prezzo_rt" select="format-number(((../../ReturnList/Return[$posrt]/Price/Amount) div ($valore_rt)) * ($eur_currency),'#.##')"/>

     <xsl:variable name="totale_finale">
      <xsl:choose>
       <xsl:when test="Price/Amount">
        <xsl:value-of select="($prezzo_ow) + ($prezzo_rt)"/>
       </xsl:when>
       <xsl:otherwise>
        <xsl:value-of select="$prezzo_unico"/>
       </xsl:otherwise>
      </xsl:choose>
     </xsl:variable>

      <item>
       <totale_finale>
        <xsl:value-of select="format-number($totale_finale,'#.##')"/>
       </totale_finale>
      </item>
    </xsl:for-each>
   </xsl:for-each>
  </xsl:for-each>
  </xsl:variable>

  <xsl:for-each select="msxsl:node-set($base)/item">
   <xsl:sort select="totale_finale" data-type="number" order="ascending"/>
   <xsl:value-of select="totale_finale"/>
   <br/>
  </xsl:for-each>

 </xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="RTRIP.xml" htmlbaseurl="" outputurl="" processortype="msxml4" useresolver="no" 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>
-->