Re: [xsl] Counting following siblings for table spans

Subject: Re: [xsl] Counting following siblings for table spans
From: "G. Ken Holman g.ken.holman@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 19 Jan 2026 19:07:10 -0000
And I hope it was obvious that I added more data by replicating selected rows to the input in order to test multiple conditions.

At 19/01/2026 19:03 +0000, G. Ken Holman g.ken.holman@xxxxxxxxx wrote:
>I hope this helps, Rick.
>
>~/t $ cat rick.xsl
><?xml version="1.0" encoding="UTF-8"?>
><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>  xmlns:xs="http://www.w3.org/2001/XMLSchema";
>  xmlns:math="http://www.w3.org/2005/xpath-functions/math";
>  exclude-result-prefixes="xs math"
>  version="3.0">
>
><xsl:mode on-no-match="shallow-copy"/>
>
><xsl:template match="cell-1">
>  <xsl:copy>
>    <xsl:copy-of select="@*"/>
>    <xsl:attribute name="rows-spanned"
>                   select="count(../following-sibling::row[empty(cell-1)]) -
>                           count(../following-sibling::row[cell-1][1]/
>                                    following-sibling::row[empty(cell-1)])
>                           + 1"/>
>  </xsl:copy>
></xsl:template>
>
></xsl:stylesheet>
>~/t $ xslt3 rick.xml rick.xsl
><?xml version="1.0" encoding="UTF-8"?><tbl>
>    <row>
>        <cell-1 rows-spanned="5"/>
>        <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 rows-spanned="3"/>
>        <cell-2>All revisions will be submitted to the FAA for review\x85</cell-2>
>        <cell-3>All revisions of this manual will be submitted to the FAA for review\x85</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 rows-spanned="2"/>
>        <cell-2>All revisions will be submitted to the FAA for review\x85</cell-2>
>        <cell-3>All revisions of this manual will be submitted to the FAA for review\x85</cell-3>
>    </row>
>    <row>
>        <cell-2>411</cell-2>
>        <cell-3>aircraft data management</cell-3>
>    </row>
>    <row>
>        <cell-1 rows-spanned="1"/>
>        <cell-2>All revisions will be submitted to the FAA for review\x85</cell-2>
>        <cell-3>All revisions of this manual will be submitted to the FAA for review\x85</cell-3>
>    </row>
></tbl>
>~/t $
>
>At 19/01/2026 18:34 +0000, rick@xxxxxxxxxxxxxx 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 review\x85</cell-2>
>>        <cell-3>All revisions of this manual will be submitted to the FAA for review\x85</cell-3>
>>    </row>
>></tbl>
>>
>>When I encounter a <cell-1> element, I need to count the immediately following ../row elements that don\x92t 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 don\x92t have <cell-1> elements. I am trying to figure out a good algorithm for doing this. Thank you.
>>
>> 
>>
>>Rick
>><http://www.mulberrytech.com/xsl/xsl-list>XSL-List info and archive 
>><http://lists.mulberrytech.com/unsub/xsl-list/96802>EasyUnsubscribe (<>by email) 
>
>
>--
>Contact info, blog, articles, etc. http://www.CraneSoftwrights.com/s/ |
>Check our site for free XML, XSLT, XSL-FO and UBL developer resources |
>Streaming hands-on XSLT/XPath 2 training class @US$50 (5 hours free!) |
>Essays (UBL, XML, etc.) http://www.linkedin.com/today/author/gkholman |
>


--
Contact info, blog, articles, etc. http://www.CraneSoftwrights.com/s/ |
Check our site for free XML, XSLT, XSL-FO and UBL developer resources |
Streaming hands-on XSLT/XPath 2 training class @US$50 (5 hours free!) |
Essays (UBL, XML, etc.) http://www.linkedin.com/today/author/gkholman |

Current Thread