I never used where-populated before. I need to look at the spec. Thank you
very much Martin!
-----Original Message-----
From: Martin Honnen martin.honnen@xxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Saturday, September 26, 2026 4:02 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: Optional wrapper in generalized for-each-group
On 26/09/2026 21:43, rick@xxxxxxxxxxxxxx wrote:
> However, I need content under a title to be wrapped in a conbody
> element, like this:
>
>
I think you get that with the following adaption of the grouping function
<xsl:function name="cp:group" as="node()*">
<xsl:param name="elements" as="element()*"/>
<xsl:param name="level" as="xs:integer"/>
<!-- Make a variable for the heading name. -->
<xsl:variable name="heading" select="'h' || $level"/>
<xsl:variable name="heading-next" select="'h' || $level + 1"/>
<xsl:for-each-group select="$elements"
group-starting-with="*[local-name() = $heading]">
<xsl:choose>
<xsl:when test="self::*[local-name() = $heading]">
<concept id="{generate-id()}">
<title>
<xsl:apply-templates/>
</title>
<xsl:sequence select="cp:group(current-group()
except ., $level + 1)"/>
</concept>
</xsl:when>
<xsl:otherwise>
<xsl:where-populated>
<conbody>
<xsl:apply-templates select="current-group()"/>
</conbody>
</xsl:where-populated>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:function>
|