+ elsif ( $node->nodeName eq 'varlistentry' ) {
+
+ foreach my $vitem ( $node->findnodes('listitem') ) {
+
+ # Add an anchorname xml attribute.
+ # chapter.xsl spots this and places a "<a id="{@anchorname}"> </a>"
+
+ my $anchorname = sprintf("vi%d", $verterm_counter++);
+ $vitem->setAttribute( 'anchorname', $anchorname );
+ $current_id = $anchorname;
+
+ # Set the latest indexable id to be picked up by the next indexterm,
+ # which should be in the content of the listitem
+
+ my ($chapter_title, $sec_id, $sec_title);
+
+ foreach my $chap ( $node->findnodes('ancestor::chapter') ) {
+ $chapter_title = $chap->findvalue('title');
+ }
+ next unless ($chapter_title);
+
+ # Search upward to find a subsection or section id & title
+ foreach my $ssec ( $node->findnodes("ancestor::section[\@level='2']") ) {
+ $sec_id = $ssec->getAttribute('id');
+ $sec_title = $ssec->findvalue('title');
+ last;
+ }
+ if (!defined($sec_id)) {
+ foreach my $sec ( $node->findnodes('ancestor::section') ) {
+ $sec_id = $sec->getAttribute('id');
+ $sec_title = $sec->findvalue('title');
+ last;
+ }
+ }
+
+ $xref->{$anchorname}{'chapter_title'} = $chapter_title;
+ $xref->{$anchorname}{'section_id'} = $anchorname;
+ $xref->{$anchorname}{'section_title'} = $sec_title if ($sec_title);
+ }
+ }