|
Subject: Re: [xsl] Counting following siblings for table spans From: "Wendell Piez wapiez@xxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Mon, 19 Jan 2026 21:25:28 -0000 |
Hello again,
Accumulators turned out to be a bit trickier than I thought, so I tried
sibling recursion, and this appears to work as well:
<xsl:template match="row/cell-1">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:attribute name="rowspan" select="1"/>
<xsl:attribute name="rowspan">
<xsl:apply-templates select="../following-sibling::*[1]"
mode="rowspan">
<xsl:with-param name="c" select="1"/>
</xsl:apply-templates>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[exists(cell-1)]" mode="rowspan" as="xs:integer">
<xsl:param name="c" required="yes"/>
<xsl:sequence select="$c"/>
</xsl:template>
<xsl:template match="*" mode="rowspan" as="xs:integer">
<xsl:param name="c" required="yes"/>
<xsl:if test="empty(following-sibling::*[1])">
<xsl:sequence select="$c"/>
</xsl:if>
<xsl:apply-templates mode="rowspan"
select="following-sibling::*[1]">
<xsl:with-param name="c" select="$c + 1"/>
</xsl:apply-templates>
</xsl:template>
Regards, Wendell
On Mon, Jan 19, 2026 at 2:07b/PM G. Ken Holman g.ken.holman@xxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> 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 |
>
>
>
--
...Wendell Piez... ...wendellpiez.com...
...pellucidliterature.org... ...pausepress.org... ...github.com/wendellpiez.
..
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Counting following siblin, G. Ken Holman g.ken. | Thread | Re: [xsl] Counting following siblin, Wendell Piez wapiez@ |
| Re: [xsl] Counting following siblin, G. Ken Holman g.ken. | Date | Re: [xsl] Counting following siblin, Liam R. E. Quin liam |
| Month |