Re: [xsl] Indexing a fop generated document.

Subject: Re: [xsl] Indexing a fop generated document.
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 17 Jan 2001 16:23:14 GMT
Sebastian> but the markup says
Sebastian> 
Sebastian>  <index links="a b c d e f"/>
Sebastian> 
Sebastian> which translates to
Sebastian> 
Sebastian>  33 24 56 2 1 3

Despite the fact that this thread has FOP in its title, I just
implemented this in xmltex (passivetex)

If you save the FO file at the end of this message as (say) xxx.fo and
save the tex code as xxx.cfg so xmltex loads the extension code for this
document then a new <fotex:sort> element is supported which takes as
content a bunch of <fo:page-number-citation> children, and sorts them
and compresses ranges so the PDF for the first page, which has an
unsorted and a sorted list of page references looks like 
2 4 2 6 4 5
2, 4-6 
Using a wrapper element rather than extra attributes has the advantage
that other FO renderers will still do something more or less sensible
with the page references if they drop through the element in the fotex
namespace. If the feature were to be officially added to FO probably
extra attributes to  fo:page-number-citation would be better (although
you might want to specify the separators (, ) and (--) as child elements
rather than attributes, to allow markup),

In this version the page numbers appearing in the sorted list are no
longer hyper links, but anyone who could remember what hyperref.sty
did with page numbers could probably improve the code to re-activate
these links.

David

<?xml version="1.0" encoding="utf-8"?>

<fo:root font-family="Times Roman" font-size="12pt" 
text-align="justified" 
xmlns:fo="http://www.w3.org/1999/XSL/Format";>
<fo:layout-master-set>
<fo:simple-page-master 
page-master-name="right" margin-top="75pt" 
margin-bottom="25pt" margin-left="100pt" 
margin-right="50pt">
<fo:region-body 
margin-bottom="50pt"/>
</fo:simple-page-master>
</fo:layout-master-set>


<fo:page-sequence  page-master="right">
<fo:flow>
<fo:block>
   <fo:page-number-citation ref-id="b"/>
   <fo:page-number-citation ref-id="f"/>
   <fo:page-number-citation ref-id="a"/>
   <fo:page-number-citation ref-id="i"/>
   <fo:page-number-citation ref-id="e"/>
   <fo:page-number-citation ref-id="g"/>
</fo:block>
<fo:block>
 <fotex:sort xmlns:fotex="http://www.tug.org/fotex";>
   <fo:page-number-citation ref-id="b"/>
   <fo:page-number-citation ref-id="f"/>
   <fo:page-number-citation ref-id="a"/>
   <fo:page-number-citation ref-id="i"/>
   <fo:page-number-citation ref-id="e"/>
   <fo:page-number-citation ref-id="g"/>
 </fotex:sort>
</fo:block>
</fo:flow>
</fo:page-sequence>


<fo:page-sequence  page-master="right">
<fo:flow>
<fo:block id="a">aaaaa</fo:block>
<fo:block id="b">bbbb</fo:block>
</fo:flow>
</fo:page-sequence>

<fo:page-sequence  page-master="right">
<fo:flow>
<fo:block id="c">ccc</fo:block>
<fo:block id="d">ddd</fo:block>
</fo:flow>
</fo:page-sequence>

<fo:page-sequence  page-master="right">
<fo:flow>
<fo:block id="e">eee</fo:block>
<fo:block id="f">fff</fo:block>
</fo:flow>
</fo:page-sequence>

<fo:page-sequence  page-master="right">
<fo:flow>
<fo:block id="g">ggg</fo:block>
<fo:block id="h">hhh</fo:block>
</fo:flow>
</fo:page-sequence>

<fo:page-sequence  page-master="right">
<fo:flow>
<fo:block id="i">iii</fo:block>
<fo:block id="j">jjj</fo:block>
</fo:flow>
</fo:page-sequence>

</fo:root>





\DeclareNamespace{fotex}{http://www.tug.org/fotex}
\DeclareNamespace{fo}{http://www.w3.org/1999/XSL/Format}

\inputonce{fotex.xmt}

\XMLelement{fo:page-number-citation}
   {\XMLattribute{ref-id}{\FOrefid}{}}
   {}
   {\fopagecitation}

\gdef\fopagecitation{\hyperlink{\FOrefid}{\pageref{\FOrefid}}}

\XMLelement{fotex:sort}
   {}
   {\let\fopagecitation\fosortpagecitation
    \global\sorttoks{}}
   {\global\sortcount-2\let\@elt\focompress@elt
    \let\fosep\@empty
    \let\foheld\relax
    \the\sorttoks
    \foheld}

\newcount\sortcount
\newtoks\sorttoks

\gdef\fosortpagecitation{
   \setbox0\hbox{\global\sortcount=0\expandafter\expandafter\expandafter
   \@secondoffive\csname r@\FOrefid\endcsname
      \relax\relax\relax\relax\relax}
    \let\@elt\fosort@elt
    \global\sorttoks\expandafter{\expandafter}\the\sorttoks
    \ifnum\sortcount<\maxdimen
   \global\sorttoks\expandafter{
       \the\expandafter\sorttoks\expandafter\@elt\expandafter{\the\sortcount}}
  \fi
    }

\gdef\fosort@elt#1{
 \ifnum#1>\sortcount
   \global\sorttoks\expandafter{\the\expandafter\sorttoks\expandafter\@elt
       \expandafter{\the\sortcount}\@elt{#1}}
  \global\sortcount\maxdimen
  \else
   \ifnum#1<\sortcount
   \global\sorttoks\expandafter{\the\sorttoks\@elt{#1}}
   \fi
 \fi
}

\gdef\focompress@elt#1{
 \global\advance\sortcount\@ne
 \ifnum#1=\sortcount
   \ifx\foheld\relax
      \edef\foheld{#1}
    \else
       \def\foheld{\textendash#1}
   \fi
  \else
   \foheld\fosep#1   
 \fi
 \global\sortcount#1
 \def\fosep{, }
} 






_____________________________________________________________________
This message has been checked for all known viruses by Star Internet delivered
through the MessageLabs Virus Control Centre. For further information visit
http://www.star.net.uk/stats.asp

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread