[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] xsl for-each and preceding-sibling


Subject: Re: [xsl] xsl for-each and preceding-sibling
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Wed, 16 Jan 2013 13:46:37 +0100

Raimund Kammering wrote:

<list>
   <entry>
     <statistics val="warn">
       <time>19:15:57</time>
       <text>something happened</text>
     </statistics>
   </entry>
   <entry>
     <statistics val="info">
       <time>19:10:50</time>
       <text>went better</text>
     </statistics>
   </entry>
   <entry>
     <statistics val="error">
       <time>15:00:00</time>
       <text>big trouble</text>
     </statistics>
   </entry>
</list>

But the problem I get with the 'summary' I want to produce using the statistics.xsl stylesheet, which looks like this:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="entry/statistics">

<xsl:for-each select=".">

That for-each select="." does not achieve anything.



<xsl:variable name="end"><xsl:value-of select="preceding-sibling::statistics[1]/time"/></xsl:variable>

The "statistics" element does not have preceding sibling elements of the same name, I think you want
<xsl:variable name="end"
select="../preceding-sibling::entry[1]/statistics/time"/>


<xsl:variable name="start"><xsl:value-of select="time"/></xsl:variable>


Doing
         <xsl:variable name="start" select="time"/>
is shorter, easier and more efficient.


Current Thread