Index with Pagenumbers
I have the following XHTML:
-----------input.xhtml---------
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>The Input file</title>
</head>
<body>
<h1 id="1.">1. Intro</h1>
<p>some text</p>
<h1 id="2.">2. Content</h1>
<p>some text</p>
... and so on ...
</body>
</html>
-------------------------
Now I would like to generate an index and after the index there should be the content.
The index should look like:
1. Intro .............................. Page 1
2. Content ............................ Page 4
. . . and so on . . .
This is the job of mkindex.xsl:
-----------mkindex.xsl---------
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet
version="1.1"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="fo"
>
<xsl:import href="style.xsl" />
<xsl:output
method="xml"
indent="no"
encoding="iso-8859-1"
omit-xml-declaration="no"
/>
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" >
<xsl:call-template name="page-def" />
<fo:page-sequence master-reference="page-master">
<xsl:call-template name="static-content" />
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates select="//xhtml:html/xhtml:body/*">
<xsl:with-param name="applyto">index</xsl:with-param>
</xsl:apply-templates>
</fo:flow>
</fo:page-sequence>
<fo:page-sequence master-reference="page-master">
<xsl:call-template name="static-content" />
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates select="//xhtml:html/xhtml:body/*">
<xsl:with-param name="applyto">style</xsl:with-param>
</xsl:apply-templates>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="xhtml:h1">
<xsl:param name="applyto" />
<xsl:if test="$applyto='index'">
<fo:block start-indent="0mm" font-size="12pt" text-align-last="justify">
<xsl:value-of select="." />
<fo:leader leader-pattern="dots" />Page
<fo:basic-link internal-destination="{@id}">
<fo:page-number-citation ref-id="{@id}" />
</fo:basic-link>
</fo:block>
</xsl:if>
<xsl:if test="$applyto='style'">
<xsl:element name="fo:block" use-attribute-sets="h1">
<xsl:value-of select="." />
</xsl:element>
</xsl:if>
</xsl:template>
<xsl:template match="xhtml:p">
<xsl:param name="applyto" />
<xsl:if test="$applyto='style'">
<xsl:element name="fo:block" use-attribute-sets="p">
<xsl:value-of select="." />
</xsl:element>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
---------------------------
After the following commands:
#xsltproc mkindex.xsl input.xhtml > /tmp/output.xhtml
#fop output.xhtml output.pdf
I get the output.pdf wich looks like this:
-----------output.pdf-------------
1. Intro .................................... Page
2. Content .................................. Page
. . . and so on . . .
-------------------------------------
But why aren't there the Page numbers where the specific h1-tags are? If i'm right you can get with <fo:basic-link internal-destination="{@id}"> the value of the id attribute of the actual node, rigth? In my case the node is h1 and the id attribute is "1.". So the value of fo:basic-link should be "1.".
And <fo:page-number-citation ref-id="{@id}" /> should go and search for a h1-tag with an id attribute with the value "1.". But it looks like there is none... or does fo:page-number-citation don't know which node is wanted?
THANKS FOR YOUR HELP
|