[xsl] xsl for-each and preceding-sibling

Subject: [xsl] xsl for-each and preceding-sibling
From: Raimund Kammering <raimund.kammering@xxxxxxx>
Date: Wed, 16 Jan 2013 13:36:47 +0100

I got stuck with a following task:

I want to process an xml file twice, first do a simple match and add some
markup to produce a line of HTML output and second want to add a kind of
summary to the top of the produced HTML. The code looks like this:

The XML is:

<?xml version="1.0" encoding="iso-8859-1"?>
    <statistics val="warn">
      <text>something happened</text>
    <statistics val="info">
      <text>went better</text>
    <statistics val="error">
      <text>big trouble</text>

Now I have two stylesheets, which look like this:

The master-stylesheet.xsl:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"

  <xsl:import href="statistics.xsl"/>

  <xsl:output method="html" omit-xml-declaration="yes"/>

  <xsl:template match="list">
    <xsl:apply-templates select="entry/statistics"/>

    <xsl:apply-templates select="entry"/>

  <xsl:template match="entry">
    <!-- process all entry elements and produce some HTML - no problems here
    <!-- so I omitt this part completely -->


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"

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

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

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

      <xsl:value-of select="$end"/><xsl:text> </xsl:text>
      <xsl:value-of select="$start"/><xsl:text> </xsl:text><xsl:value-of
select="@val"/><xsl:text>: </xsl:text><xsl:value-of select="text"/><xsl:text>



The output I get is:

 19:15:57 warn: something happened
 19:10:50 info: went better
 15:00:00 error: big trouble

But what I want to achieve is:

19:10:50 19:15:57  warn: something happened
15:00:00 19:10:50 info: went better
 15:00:00 error: big trouble

(yes I know, it will have a problem on the first node, but I guess if I get
preceding-sbiling done, I'll be able to do the rest myself ;)

The XSLT is done using the java implementation of Xalan (extract from the

Name: org/apache/xalan/
Comment: Main Xalan engine implementing TrAX/JAXP
Specification-Title: Java API for XML Processing
Specification-Vendor: Sun Microsystems Inc.
Specification-Version: 1.3
Implementation-Title: org.apache.xalan
Implementation-Version: 2.7.0
Implementation-Vendor: Apache Software Foundation
Implementation-URL: http://xml.apache.org/xalan-j/

(yes I know it is a very old version, but I guess this is not the origin of
the problem)

I already tried various slight modifications to get the preceding element but
always fail to access any other than the current node! Do I completely
misunderstand something here (I'm not really working frequently with XSL!)

Any help would be greatly appreciated!

Current Thread