tags:

views:

50

answers:

2

In the if block below I want to be also test whether @Timestamp is smaller than the previous Message's timestamp. How can I achieve this?

<xsl:for-each select="Message">
    <xsl:sort select="position()" data-type="number" order="descending"/>
    <xsl:variable name="newclass">
        <xsl:if test="@Timestamp + 60 &gt; $ctimestamp">new</xsl:if>
    </xsl:variable>

    <tr><td class="debugtime">
        <xsl:value-of select="@Time"/>
    </td><td class="{$newclass}">
        <xsl:value-of select="node()"/>
    </td></tr>
</xsl:for-each>

Example XML

<Message Time="2010/06/17 04:23:32" Timestamp="1276773812">message1</Message>
<Message Time="2010/06/17 04:23:32" Timestamp="1276773812">message2</Message>
<Message Time="2010/06/17 04:23:33" Timestamp="1276773813">message3</Message>
<Message Time="2010/06/17 04:23:33" Timestamp="1276773813">message4</Message>

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 if block code below.

<xsl:if test="@Timestamp + 60 &gt; $ctimestamp">
    <xsl:if test="position() = 1">
        new
    </xsl:if>
    <xsl:if test="position() != 1 and ../Message[position()-1]/@Timestamp - 1 &lt; @Timestamp">
        new
    </xsl:if>
</xsl:if>
A: 
@Timestamp &lt; preceding-sibling::Message[1]/@Timestamp
Max Toro
Forgot about XPath Axeses,but perhaps it should be@Timestamp < preceding-sibling::Message[position()+1]/@Timestampdepending on what XPath chooses to give us.
Meiscooldude
Please see my update, I tried your implementation as well as the one currently listed in my updated code. I also tried @Meiscooldude's variation
Chris
@Chris: Please see my updated answer.
Max Toro
Thanks Max - This seems to alternately bold every other line i.e. 1,3,5,7 etc
Chris
Ah... got it working with `following-sibling` as opposed to `preceeding-sibling` - thanks
Chris
@Chris: I don't understand, I thought you wanted to compare with the previous Message, why are you using `following-sibling` ?
Max Toro
A: 

I haven't tested this solution, but this should do you.

<xsl:for-each select="Message">
    <xsl:sort select="position()" data-type="number" order="descending"/>

    <xsl:variable name="newclass">
      <xsl:if test="position() != 1">
         <xsl:if test="..\Message[position()-1]@Timestamp &lt; @Timestamp">new</xsl:if>
      </xsl:if>
      <xsl:if test="position() = 1">
         new
      </xsl:if>
    </xsl:variable>

   <tr><td class="debugtime">
       <xsl:value-of select="@Time"/>
   </td><td class="{$newclass}">
       <xsl:value-of select="node()"/>
   </td></tr>

</xsl:for-each>
Meiscooldude
Please see my update
Chris