From 823d5e910b06dab984445f59399fa0ad39eba3ea Mon Sep 17 00:00:00 2001 From: Nigel Metheringham Date: Sun, 4 Jul 2010 14:25:42 +0100 Subject: [PATCH] Add id tags to chapters/sections missing them --- script/gen.pl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/script/gen.pl b/script/gen.pl index 4c545f5..1fbb026 100755 --- a/script/gen.pl +++ b/script/gen.pl @@ -163,7 +163,11 @@ sub xref_fixup { foreach my $chapter ( $xml->findnodes('/book/chapter') ) { ++$chapter_counter; - my $chapter_id = $chapter->getAttribute('id'); + my $chapter_id = $chapter->getAttribute('id'); + unless ($chapter_id) { # synthesise missing id + $chapter_id = sprintf( 'chapter_noid_%04d', $chapter_counter ); + $chapter->setAttribute( 'id', $chapter_id ); + } my $chapter_title = $chapter->findvalue('title'); $index{$chapter_id} = { chapter_id => $chapter_counter, chapter_title => $chapter_title }; @@ -173,7 +177,11 @@ sub xref_fixup { foreach my $section ( $chapter->findnodes('section') ) { ++$section_counter; - my $section_id = $section->getAttribute('id'); + my $section_id = $section->getAttribute('id'); + unless ($section_id) { # synthesise missing id + $section_id = sprintf( 'section_noid_%04d_%04d', $chapter_counter, $section_counter ); + $section->setAttribute( 'id', $section_id ); + } my $section_title = $section->findvalue('title'); $index{$section_id} = -- 2.30.2