[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

xsl for-each and preceding-sibling

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

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"?>
<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>

Now I have two stylesheets, which look like this:

The master-stylesheet.xsl:

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

  <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>

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

</xsl:stylesheet>

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=".">

      <xsl:variable name="end"><xsl:value-of
select="preceding-sibling::statistics[1]/time"/></xsl:variable>
      <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>
</xsl:text>
    </xsl:for-each>

  </xsl:template>

</xsl:stylesheet>

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
MANIFEST.MF):

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!
Raimund

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.