+
+ # 2022/07/07 jgh: added loop for sections under sections, which are resulting from the .subsection macro
+ # Add a "level" attribute to these nodes
+ ## Iterate over each subsection
+ my $subsec_counter = 0;
+ foreach my $subsection ( $section->findnodes('section') ) {
+ ++$subsec_counter;
+
+ $subsection->setAttribute( 'level', "2" );
+ $subsection->setAttribute( 'sectprefix', sprintf("%d.%d", $section_counter, $subsec_counter) );
+
+ my $subsec_id = $subsection->getAttribute('id');
+ unless ($subsec_id) { # synthesise missing id
+ $subsec_id = sprintf( 'section_noid_%04d_%04d_%04d', $chapter_counter, $section_counter, $subsec_counter );
+ $subsection->setAttribute( 'id', $subsec_id );
+ }
+ my $subsec_title = $subsection->findvalue('title');
+
+ $index{$subsec_id} = {
+ chapter_id => $chapter_counter,
+ chapter_title => $chapter_title,
+ section_id => $subsec_counter,
+ section_title => $subsec_title
+ };
+ }