RE: matching nodes and counting columns

Subject: RE: matching nodes and counting columns
From: Ben Robb <Ben@xxxxxxxxxx>
Date: Tue, 15 Aug 2000 09:58:30 +0100
> How can I apply one template to first <table> and another 
> template to the
> second <table>,
> or how can I skip first and third tables and apply template 
> to the second
> only?
Either name your templates, and use xsl:call-template, or create more
specific templates for your tables. If they have distinguishing features,
use filters in your XPath expressions:

e.g.

<xsl:template match="table[@name='useMe']">

Or, if they do not, and you are certain that you can say where in the
document the special cases are, use the position() method in your XPath
statement:

<xsl:template match="table[position() = 2]">

which will take the nodeset created when you call the <xsl:apply-templates
/> method on the <body> node, and apply this particular template to the
second node.

Or, if you were only interesting in processing the one specific table
element (and its children), and no other child of the body tag, you could
use the select attribute in <xsl:apply-templates />, using the same XPath
statements and filters as above.


> 2. <table> tag in wml requires columns attribute with number 
> of colums.
> So actually I need to count number of <td> in first <tr> of the table
> (lets say there are no colspans and rowspans in html)
> <xsl:value-of select="count(tr/td)" /> - gives me a number of 
> all <td> in
> the table
> I found a way out:
> <xsl:value-of select="count(tr/td) div count(tr) "/>
> (to divide number of cells by number of rows :-))
> but that is probably not the best way doing it

Thats as elegant a way as any other. Though you could probably extend it to
account for rowspan and colspan attributes to make it more generic.

Ben


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


Current Thread