title: xsl:if first and last node not retrieved
body: <p>I have an XML as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  &lt;ExistingReservations&gt;
      &lt;reservations&gt;
          &lt;reservation&gt;
              &lt;type&gt;1&lt;/type&gt;
              &lt;start_time&gt;2019-03-09T16:11:14Z&lt;/start_time&gt;
              &lt;stop_time&gt;2019-03-09T16:23:23Z&lt;/stop_time&gt;
          &lt;/reservation&gt;
          &lt;reservation&gt;
              &lt;type&gt;2&lt;/type&gt;
              &lt;start_time&gt;2019-03-09T11:23:12Z&lt;/start_time&gt;
              &lt;stop_time&gt;2019-03-09T11:32:18Z&lt;/stop_time&gt;
          &lt;/reservation&gt;
          &lt;reservation&gt;
              &lt;type&gt;2&lt;/type&gt;
              &lt;start_time&gt;2019-03-09T12:23:12Z&lt;/start_time&gt;
              &lt;stop_time&gt;2019-03-09T12:32:18Z&lt;/stop_time&gt;
          &lt;/reservation&gt;
      &lt;/reservations&gt;
  &lt;/ExistingReservations&gt;
  </code></pre>
  
  <p>I want to only look at reservations of type '2' and then get the range of dates. i.e. the first start_time and the last end time.</p>
  
  <p>But i'm struggling with my xsl as I can't seem to get the first and last positions.</p>
  
  <p>My xsl is as follows:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;
      &lt;xsl:template match="ExistingReservations"&gt;
          &lt;ReservationSchedule&gt;
              &lt;xsl:for-each select="//reservation"&gt;
                  &lt;xsl:if test="type='2'"&gt;
                      &lt;period&gt;
                          &lt;xsl:if test="position()=1"&gt;
                              &lt;start_time&gt;&lt;xsl:value-of select="start_time"/&gt;&lt;start_time&gt;
                          &lt;/xsl:if&gt;
  
                          &lt;xsl:if test="position() = last()"&gt;
                              &lt;end_time&gt;&lt;xsl:value-of select="stop_time"/&gt;&lt;/end_time&gt;
                          &lt;/xsl:if&gt;
  
                      &lt;/period&gt;
                  &lt;/xsl:if&gt;
              &lt;/xsl:for-each&gt;
          &lt;/ReservationSchedule&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>So I want to transform to the following:</p>
  
  <pre><code>&lt;ReservationSchedule&gt;
      &lt;period&gt;
          &lt;start_time&gt;2019-03-09T11:23:12Z&lt;/start_time&gt;
          &lt;end_time&gt;2019-03-09T12:32:18Z&lt;/end_time&gt;
      &lt;/period&gt;
  &lt;/ReservationSchedule&gt;
  </code></pre>
  
  <p>I think in the <code>&lt;xsl:if test="position()=1"&gt;</code> is not working because it's looking at the first node whichi s type 1.. i.e. it's igoring the <code>&lt;xsl:if test="type='2'"&gt;</code> logic.</p>
  
  <p>Any help appreciated.</p>