Re: [xsl] Nested grouping using group-starting-with - brief code review?

Subject: Re: [xsl] Nested grouping using group-starting-with - brief code review?
From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx>
Date: Mon, 17 May 2010 16:26:50 +0200
Dear Peter,

For just 2 levels of nested grouping, your approach seems reasonable. A more generic approach using recursive grouping (and permitting gaps in hierarchy, for example h3 following h1) may be found here:
http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/201004/msg00124.html
Since this was meant for ToC generation, you'll have to replace all the <ul> stuff with <section> as appropriate, and remove the comment on the line below "<!-- no output for non-headings, as we are creating the ToC: -->".


Hope this helps.

Gerrit


On 17.05.2010 16:04, Peter Desjardins wrote:
Hi.

I'm writing a 2.0 stylesheet to wrap sections of an HTML document in
<section>  elements. This is part of a conversion to an XML doc format
such as DocBook or DITA. I'm very new to XSLT. My processor is Saxon
HE 9.2.1.1.

Based on a technique I was given in the following post, I've nested
grouping levels to handle h1, h2, and h3 elements.

http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/201005/msg00105.html

For each heading level except the lowest (h3 in my case) I have
included another<xsl:for-each-group>  element inside the<section>
element in the template. This gives the output I was hoping for.

<xsl:template match="h1" mode="group-level-one">
     <xsl:element name = "section">
         <xsl:for-each-group select = "current-group()"
group-starting-with = "h2">
             <xsl:apply-templates select="." mode="group-level-two"/>
         </xsl:for-each-group>
     </xsl:element>
</xsl:template>

Is this a reasonable way to handle nested grouping? I would appreciate
any suggestions for improvment.

Here are my full stylesheet, source, and output.

      https://sites.google.com/site/filessharedbypeter/Home/wrap-doc-sections.xsl
      https://sites.google.com/site/filessharedbypeter/Home/source.xml
      https://sites.google.com/site/filessharedbypeter/Home/output.xml

Thanks for your help.

Peter


-- Gerrit Imsieke Geschdftsf|hrer / Managing Director le-tex publishing services GmbH Weissenfelser Str. 84, 04229 Leipzig, Germany Phone +49 341 355356 110, Fax +49 341 355356 510 gerrit.imsieke@xxxxxxxxx, http://www.le-tex.de

Registergericht / Commercial Register: Amtsgericht Leipzig
Registernummer / Registration Number: HRB 24930

Geschdftsf|hrer: Gerrit Imsieke, Svea Jelonek,
Thomas Schmidt, Dr. Reinhard Vvckler

Current Thread