|
Subject: Re: [xsl] Counting following siblings for table spans From: "David Carlisle d.p.carlisle@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Mon, 19 Jan 2026 19:06:32 -0000 |
I get row 1 cell-1 rowspan 5 row 1 cell-2 rowspan 1 row 1 cell-3 rowspan 1 row 2 cell-2 rowspan 1 row 2 cell-3 rowspan 1 row 3 cell-2 rowspan 1 row 3 cell-3 rowspan 1 row 4 cell-2 rowspan 1 row 4 cell-3 rowspan 2 row 5 cell-2 rowspan 1 from <xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:d="data:,data"> <xsl:template match="row/*"> <xsl:message select="'row',1+count(../preceding-sibling::row), name(), 'rowspan', d:span(.,1)"/> </xsl:template> <xsl:function name="d:span"> <xsl:param name="e"/> <xsl:param name="n"/> <xsl:sequence select="if($e/../following-sibling::*[$n]/*[name()=name($e)]) then $n else d:span($e,$n+1) "/> </xsl:function> </xsl:stylesheet> David On Mon, 19 Jan 2026 at 19:03, Wendell Piez wapiez@xxxxxxxxxxxxxxx < xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > 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... > XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list> > EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/2739265> (by > email <>)
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Counting following siblin, Wendell Piez wapiez@ | Thread | Re: [xsl] Counting following siblin, Liam R. E. Quin liam |
| Re: [xsl] Counting following siblin, Wendell Piez wapiez@ | Date | Re: [xsl] Counting following siblin, G. Ken Holman g.ken. |
| Month |