Forum How do I...?

Duplicated page numbers in Index

vkushnir
Hi there,

I've seen this topic:
http://www.princexml.com/forum/topic/1756/index-generation-using-princexml-8?p=1#8398

I have a similar problem. The HTML and CSS file are attached. So, I'm curious is there any chance to generate PDF file from this HTML and CSS (with JS or something else) without duplicated pages and without a two-pass process in Prince 10?

- Sincerely, Volodymyr

- Sincerely, Volodymyr

  1. main.css2.1 kB
    CSS file
  2. userguide.pdf620.1 kB
    output pdf file
  3. userguide.xhtml642.8 kB
    input HTML file
mikeday
Yes, but it's complicated. Say you have three occurrences of a term, so your index entry for that term needs to check those three page numbers and handle them appropriately. The only way to do this is to pass all three to a JavaScript function via CSS generated content:
term: <span style="content: prince-script(indexEntry, target-counter(url(#term1), page), target-counter(url(#term2), page), target-counter(url(#term3), page)"></span>

The function will take a variable number of arguments:
Prince.addScriptFunc("indexEntry", function() {
    var str = "";
    var prev = -1;
    for (var i = 0; i < arguments.length; ++i) {
        var n = Number(arguments[i]);
        if (n != prev) {
            if (prev != -1) str += ", ";
            str += n;
            prev = n;
        }
    }
    return str;
});

Note, I haven't actually tested this code, but it shows the rough outline. It has a limitation in that it can only return an undecorated text string, so you can't make individual page references bold or italic, that would require treating each page reference as a separate element, inhibiting the ability to combine identical page numbers.
dcowens76
I am very interested in this, but fiddling with Javascript is beyond my abilities. We are using Prince to typeset books, so we need to be able to generate an index with many pages referenced. Has anyone tested this code?
vkushnir
Hi dcowens76,

I decided to use a two-pass process in Prince 10. And it works without duplicated page numbers in Index. If you are working with DITA-OT, you may check out this plugin to generate PDF file from .ditamap.

- Sincerely, Volodymyr

Edited by vkushnir