|
Subject: Re: [xsl] Counting following siblings for table spans From: "rick@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 20 Jan 2026 14:10:17 -0000 |
Thank you all for the great suggestions. I ended up using grouping. Here is a simple stylesheet where I don't account for column straddles for cell-1 elements because I know my data doesn't require them. <?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:cp="http://www.frameexpert.com/functions" exclude-result-prefixes="xs cp" version="3.0" expand-text="yes"> <xsl:output indent="yes"/> <xsl:template match="/tbl"> <Tbl> <xsl:for-each-group select="row" group-starting-with="row[cell-1]"> <xsl:apply-templates select="current-group()"/> </xsl:for-each-group> </Tbl> </xsl:template> <xsl:template match="row"> <Row><xsl:apply-templates/></Row> </xsl:template> <xsl:template match="cell-1"> <xsl:variable name="rowSpan" select="count(current-group())"/> <Cell> <xsl:if test="$rowSpan gt 1"> <xsl:attribute name="rowSpan" select="$rowSpan"/> </xsl:if> <xsl:value-of select="."/> </Cell> </xsl:template> <xsl:template match="cell-2|cell-3"> <xsl:variable name="colSpan"> <xsl:if test="not(following-sibling::cell-3)"> <xsl:value-of select="'2'"/> </xsl:if> </xsl:variable> <Cell> <xsl:if test="$colSpan!=''"> <xsl:attribute name="colSpan" select="$colSpan"/> </xsl:if> <xsl:value-of select="."/> </Cell> </xsl:template> <xsl:mode on-no-match="shallow-skip"/> </xsl:stylesheet> From: rick@xxxxxxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Sent: Monday, January 19, 2026 1:34 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] Counting following siblings for table spans 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.</cell-2> <cell-3>All revisions of this manual will be submitted to the FAA for review.</cell-3> </row> </tbl> When I encounter a <cell-1> element, I need to count the immediately following ../row elements that don't 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't 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> <http://lists.mulberrytech.com/unsub/xsl-list/612310> EasyUnsubscribe ( <> by email)
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Counting following siblin, Liam R. E. Quin liam | Thread | [xsl] Practices to handle parameter, Schimon Jehudah sch@ |
| Re: [xsl] Counting following siblin, Liam R. E. Quin liam | Date | [xsl] Practices to handle parameter, Schimon Jehudah sch@ |
| Month |