Re: [xsl] Counting following siblings for table spans

Subject: Re: [xsl] Counting following siblings for table spans
From: "Wendell Piez wapiez@xxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 19 Jan 2026 19:03:28 -0000
Rick,

I think your requirement can be translated directly. First -

count(../following-sibling::row[empty(child::cell-1)])

If you want to start the count at 1, not zero, I usually do something like

count(../(. | following-sibling::row[empty(child::cell-1)] ))

This includes the parent row element in the count. (Some people would just
add 1.)

However, by "immediately following" you probably mean there can be no
cell-1 row intervening. XPath has a couple of ways to do this.

For example, a similar path can be used to identify all the subsequent rows
with a child-1, and their following siblings, then you can exclude those
from the count. So you have two sequences:

$including =  ../(. | following-sibling::row[empty(child::cell-1)] )  (:
this row, plus following sibling rows with no cell-1 :)
$excluding = ../following-sibling::row[exists(child::cell-1)] / (. |
following-sibling::row)  (: following rows with cell-1, plus their
following siblings with or without cell-1 :)

count($including except $excluding) should be the count you want. (Not
tested!)

Another, perhaps more elegant and performant solution would be to use an
XSLT accumulator, not XPath.

HTH, Wendell





HTH, Wendell




On Mon, Jan 19, 2026 at 1:34b/PM rick@xxxxxxxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> Hi All,
>
>
>
> I have table data like this:
>
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <tbl>
>     <row>
>         <cell-1>Throughout</cell-1>
>         <cell-2>log book</cell-2>
>         <cell-3>logbook</cell-3>
>     </row>
>     <row>
>         <cell-2>AirVault</cell-2>
>         <cell-3>Aircraft Records Database</cell-3>
>     </row>
>     <row>
>         <cell-2>411</cell-2>
>         <cell-3>aircraft data management</cell-3>
>     </row>
>     <row>
>         <cell-2>Status Report</cell-2>
>         <cell-3>MDR</cell-3>
>     </row>
>     <row>
>         <cell-2>Removed M-Facility Directors (MFD)</cell-2>
>     </row>
>     <row>
>         <cell-1>1 / 1-2</cell-1>
>         <cell-2>All revisions will be submitted to the FAA for
> reviewb&</cell-2>
>         <cell-3>All revisions of this manual will be submitted to the FAA
> for reviewb&</cell-3>
>     </row>
> </tbl>
>
> When I encounter a <cell-1> element, I need to count the immediately
> following ../row elements that donbt have a <cell-1> child so I can
> determine the row span value. In my example, the <cell-1> element would
> span the following 4 rows because they donbt have <cell-1> elements. I am
> trying to figure out a good algorithm for doing this. Thank you.
>
>
>
> Rick
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/174322> (by
> email <>)
>


--
...Wendell Piez... ...wendellpiez.com...
...pellucidliterature.org... ...pausepress.org... ...github.com/wendellpiez.
..

Current Thread