title: XSL - Get attribute of previous element
body: <p>In the <code>if</code> block below I want to be also test whether <code>@Timestamp</code> is smaller than the previous <code>Message</code>'s timestamp.  How can I achieve this?</p>
  
  <pre><code>&lt;xsl:for-each select="Message"&gt;
      &lt;xsl:sort select="position()" data-type="number" order="descending"/&gt;
      &lt;xsl:variable name="newclass"&gt;
          &lt;xsl:if test="@Timestamp + 60 &amp;gt; $ctimestamp"&gt;new&lt;/xsl:if&gt;
      &lt;/xsl:variable&gt;
  
      &lt;tr&gt;&lt;td class="debugtime"&gt;
          &lt;xsl:value-of select="@Time"/&gt;
      &lt;/td&gt;&lt;td class="{$newclass}"&gt;
          &lt;xsl:value-of select="node()"/&gt;
      &lt;/td&gt;&lt;/tr&gt;
  &lt;/xsl:for-each&gt;
  </code></pre>
  
  <p>Example XML</p>
  
  <pre><code>&lt;Message Time="2010/06/17 04:23:32" Timestamp="1276773812"&gt;message1&lt;/Message&gt;
  &lt;Message Time="2010/06/17 04:23:32" Timestamp="1276773812"&gt;message2&lt;/Message&gt;
  &lt;Message Time="2010/06/17 04:23:33" Timestamp="1276773813"&gt;message3&lt;/Message&gt;
  &lt;Message Time="2010/06/17 04:23:33" Timestamp="1276773813"&gt;message4&lt;/Message&gt;
  </code></pre>
  
  <p>Update:
  I have implemented both variations of the current answers but to no luck.  It always doesn't seem to work properly for the second elements onwards, in that it will bold the first correctly but no more (although sometimes it will do the third).  Updated <code>if</code> block code below.</p>
  
  <pre><code>&lt;xsl:if test="@Timestamp + 60 &amp;gt; $ctimestamp"&gt;
      &lt;xsl:if test="position() = 1"&gt;
          new
      &lt;/xsl:if&gt;
      &lt;xsl:if test="position() != 1 and ../Message[position()-1]/@Timestamp - 1 &amp;lt; @Timestamp"&gt;
          new
      &lt;/xsl:if&gt;
  &lt;/xsl:if&gt;
  </code></pre>