title: How to find and format latest date from multiple fields in xslt
body: <p>I have searched for info on my specific scenario and did not find what I'm looking for. Apologies up front if I missed something.  </p>
  
  <p>I am looking for help on syntax for finding and formatting the latest date out of a set of three fields.  I am able to sloppily find the latest date and am able to format a date, but putting the syntax all together and getting it to work properly is eluding me.  I wanted to ask this forum for a clean code to do the following:
  Using xslt 2.0 find, return and format the latest date out of these three fields - format of '20070724' :
              -ws:Pay_Rate_Type_Change_Effective_Date
              -ws:Time_Type_Change_Effective_Date
              -ws:Job_Code_Change_Effective_Date  </p>
  
  <p>Any help much appreciated!</p>
  
  <p>Thanks,
  Jenn</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;ws:Worker_Sync xmlns:ws="urn:com.workday/workersync"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  
  &lt;ws:Worker&gt;
      &lt;ws:Summary&gt;
          &lt;ws:Employee_ID&gt;123456&lt;/ws:Employee_ID&gt;
      &lt;/ws:Summary&gt;
      &lt;ws:Additional_Information&gt;
          &lt;ws:Time_Type_Change_Effective_Date&gt;2005-05-24&lt;/ws:Time_Type_Change_Effective_Date&gt;
          &lt;ws:Pay_Rate_Type_Change_Effective_Date&gt;2006-06-24&lt;/ws:Pay_Rate_Type_Change_Effective_Date&gt;
          &lt;ws:Job_Code_Change_Effective_Date&gt;2007-07-24&lt;/ws:Job_Code_Change_Effective_Date&gt;
      &lt;/ws:Additional_Information&gt;
  &lt;/ws:Worker&gt;    
  &lt;/ws:Worker_Sync&gt;
  
  
  &lt;?xml version='1.0'?&gt;
  &lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:ws="urn:com.workday/workersync" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xtt="urn:com.workday/xtt" xmlns:etv="urn:com.workday/etv"
  xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wd="urn:com.workday.report"&gt;
  &lt;!-- set encoding of output - need to create a properly formatted XML document that Workday's internal document transformation engine will convert to a text file --&gt;
  &lt;xsl:output method="xml" encoding="UTF-8"/&gt;
  
  &lt;xsl:template match="/"&gt;
      &lt;File xtt:separator="&amp;#xd;&amp;#xa;"&gt;
          &lt;xsl:variable name="linefeed" select="'&amp;#xa;'"/&gt;
          &lt;xsl:variable name="currentDate"&gt;
              &lt;xsl:value-of select="format-date(current-date(), '[Y0001][M01][D01]')"/&gt;
          &lt;/xsl:variable&gt;
          &lt;xsl:apply-templates select="ws:Worker_Sync/ws:Worker"/&gt;
      &lt;/File&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="/ws:Worker_Sync/ws:Worker"&gt;
      &lt;Record xtt:separator="|"&gt;
          &lt;EmployeeAssignedID&gt;
              &lt;xsl:value-of select="ws:Summary/ws:Employee_ID"/&gt;
          &lt;/EmployeeAssignedID&gt;            
          &lt;RecordChangeEffectiveDate/&gt;         &lt;!--FT/PT, Hrly/Slry, Jobcode change effdt--&gt;
          &lt;!--Here is where I have to add code to say:
          Find, return and format the latest date out of these three fields in xml file - format of '20070724' :
          -ws:Pay_Rate_Type_Change_Effective_Date
          -ws:Time_Type_Change_Effective_Date
          -ws:Job_Code_Change_Effective_Date    --&gt;   
      &lt;/Record&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>