title: Translating month names into number using only XSL version 1.0
body: <p>I'm pulling in a custom XML feed from a client's server. I have no control over this XML format. In order to restructure the XML structure I'm using XSLT by running <a href="http://man.cx/wget" rel="nofollow">wget</a> and <a href="http://man.cx/xsltproc" rel="nofollow">xsltproc</a> to apply a custom style sheet under RHEL 5. Things are working just fine until when we need to do a bit of date conversions. </p>
  
  <p>The feed coming is as such...</p>
  
  <pre><code>...
  &lt;event&gt;
     &lt;date&gt;October 3, 2013&lt;/date&gt;
     &lt;time&gt;2:00 PM - 4:00 PM&lt;/time&gt;
     &lt;moar_xml_here/&gt;
  &lt;/event&gt;
  ...
  </code></pre>
  
  <p>However I need a distinct <code>&lt;startDateTime&gt;</code> and <code>&lt;endDateTime&gt;</code>. </p>
  
  <p>I'm currently converting the date portion in a template as follows. I'm looking over this code and wondering if there is a better way.</p>
  
  <pre><code>&lt;xsl:template match="date"&gt;
      &lt;!-- year first --&gt;
      &lt;xsl:value-of select="normalize-space(substring-after(., ','))"/&gt;
  
      &lt;!-- month  --&gt;
      &lt;xsl:choose&gt;
          &lt;xsl:when test="contains(., 'January')"&gt;
              &lt;xsl:value-of select="-01"/&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:when test="contains(., 'February')"&gt;
              &lt;xsl:value-of select="-02"/&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:when test="contains(., 'March')"&gt;
              &lt;xsl:value-of select="-03"/&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:when test="contains(., 'April')"&gt;
              &lt;xsl:value-of select="-04"/&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:when test="contains(., 'May')"&gt;
              &lt;xsl:value-of select="-05"/&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:when test="contains(., 'June')"&gt;
              &lt;xsl:value-of select="-06"/&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:when test="contains(., 'July')"&gt;
              &lt;xsl:value-of select="-07"/&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:when test="contains(., 'August')"&gt;
              &lt;xsl:value-of select="-08"/&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:when test="contains(., 'September')"&gt;
              &lt;xsl:value-of select="-09"/&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:when test="contains(., 'October')"&gt;
              &lt;xsl:value-of select="-10"/&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:when test="contains(., 'November')"&gt;
              &lt;xsl:value-of select="-11"/&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:when test="contains(., 'December')"&gt;
              &lt;xsl:value-of select="-12"/&gt;
          &lt;/xsl:when&gt;
      &lt;/xsl:choose&gt;
  
      &lt;!-- Get everything before the comma, find the position of the space, and return the remaining value (day as date) --&gt;
      &lt;xsl:variable name="working_to_day" select="normalize-space(substring-before(. , ','))"/&gt;
  
      &lt;xsl:variable name="space_pos" select="string-length(normalize-space(substring-before(. , ' ')))+1"/&gt;
  
      &lt;xsl:value-of select="string('-')"/&gt;
      &lt;xsl:value-of select="normalize-space(translate(substring($working_to_day, $space_pos), ' ', '0'))"/&gt;
  &lt;/xsl:template&gt;
  </code></pre>