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
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--