## Generate the chapters
my $counter = 0;
- foreach my $chapter ( map { $_->cloneNode(1) } $xml->findnodes('/book/chapter') ) {
+ my @chapters = map { $_->cloneNode(1) } $xml->findnodes('/book/chapter');
+ foreach my $chapter ( @chapters ) {
## Add a <chapter_id>N</chapter_id> node for the stylesheet to use
$chapter->appendTextChild( 'chapter_id', ++$counter );
? 'filter.html'
: 'index.html'
: sprintf( '%sch%02d.html', $prepend_chapter, $counter - 1 ) );
- $chapter->appendTextChild( 'next_url', sprintf( '%sch%02d.html', $prepend_chapter, $counter + 1 ) );
+ $chapter->appendTextChild( 'next_url', sprintf( '%sch%02d.html', $prepend_chapter, $counter + 1 ) ) unless int(@chapters) == $counter;
$chapter->appendTextChild(
'canonical_url',
sprintf(
<!-- Navigation -->
<a class="previous_page" href="{prev_url}"><![CDATA[<-previous]]></a>
- <a class="next_page" href="{next_url}"><![CDATA[next->]]></a>
+ <xsl:if test="next_url">
+ <a class="next_page" href="{next_url}"><![CDATA[next->]]></a>
+ </xsl:if>
<!-- Chapter Wrapper -->
<div id="chapter" class="chapter{@class}">