Re: [xsl] Another beginner question about position() counting using recursi ve templates

Subject: Re: [xsl] Another beginner question about position() counting using recursi ve templates
From: Greg Faron <gfaron@xxxxxxxxxxxxxxxxxx>
Date: Mon, 08 Apr 2002 10:05:24 -0600
At 09:15 AM 4/8/2002, you wrote:
I want counting all cols from 1 to 8 and then assigning every number to an
id attrribute, idependent from their relative context node.
I am trying to assign a parameter and then select this  <xsl:value-of
select="$datacells" />.

Now i am getting 1 2 3 4
                   1 2 3 4

which is no wonder because that is in fact the position() relative to the
context node.

I have no idea how to get the param datacells outputting:

                1 2 3 4
                5 6 7 8

Instead of position(), use the number of preceding row or col elements as your basis. Remember that you'll need to add 1 for the current node. Here's your stylesheet:


<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="/">
<html>
<head>
<title>tabelle.xsl</title>
</head>
<body bgcolor="#cccccc" text="#000000" link="#455fbe" vlink="#455fbe" alink="#FF9900" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" id="output">
<div align="center">
<xsl:apply-templates select="tabelle"/>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="tabelle">
<table cellpadding="0" cellspacing="0" border="1" align="center">
<xsl:apply-templates select="row"/>
</table>
</xsl:template>
<xsl:template match="row">
<tr>
<xsl:attribute name="id"><xsl:number value="count(preceding::row) + 1" format="1"/></xsl:attribute>
<xsl:apply-templates select="col"/>
</tr>
</xsl:template>
<xsl:template match="col">
<xsl:param name="datacells" select="count(preceding::col) + 1"/>
<td>
<xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
<xsl:attribute name="id"><xsl:value-of select="$datacells"/></xsl:attribute>
<xsl:value-of select="."/>
</td>
</xsl:template>
</xsl:stylesheet>



Greg Faron Integre Technical Publishing Co.



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list


Current Thread