Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 15th, 2006, 10:53 AM
Registered User
 
Join Date: Feb 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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







Similar Threads
Thread Thread Starter Forum Replies Last Post
Index carumuga SQL Server 2000 1 December 31st, 2007 12:42 PM
z-index and ie7 fredzbooks BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 0 August 25th, 2007 07:44 AM
Index Server darkestangel1980 ASP.NET 1.0 and 1.1 Basics 0 August 18th, 2007 06:56 AM
Index question Gert SQL Server 2000 3 February 26th, 2004 05:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.