Next in thread → Next in month →

Re: [docbook-apps] Incorrect page numbers in index for indexterms within mediaobjects?

From
Bob Stayton <>
Date
2008-09-30T23:57:14+00:00
ID
001001c92358$946dd550$6a00a8c0@pazu
Thread
Re: [docbook-apps] Incorrect page numbers in index for indexterms within mediaobjects?
Well, this is more complicated than it should be, 
it seems.

 

That customization does work for me when I process 
with xep.extensions=1 and XEP 4.13.  I get this in the index:

 

Index

T
TEST, 
1, 4
TEST2, 2
TEST3, 3

When xep.extensions=1, indexterms  are handled 
as a special case in the stylesheet because of the extensions that XEP provides 
for collapsing duplicate page numbers and creating ranges of pages.  So 
there is no comparing XEP with other FO processors when it comes to 
indexterms.

 

My customization should work in Antenna House, but 
there are two bugs in the template named info.reference which is used 
when handling indexterms inside info elements.  That template comes 
into play for non-XEP index processing, that is, when xep.extensions = 
0. 

 

This customization of info.reference fixes the 
problem in Antenna House.  I added ancestor::mediaobject to the list for 
the variable named target since it was missing, and I changed the [1] predicate 
to [position() = last()], because when ancestor lists are placed in parens, they 
are converted to document order rather than most recent ancestor order. 

 

 

<xsl:template 
name="info.reference">
  <!-- This is not perfect. It doesn't 
treat indexterm inside info element as a range covering whole parent of 
info.
       It also not work when there is no 
ID generated for parent element. But it works in the most common cases. 
-->
  <xsl:param name="scope" select="."/>
  
<xsl:param name="role" select="''"/>
  <xsl:param name="type" 
select="''"/>

 

  <xsl:variable name="target" 
select="(ancestor::appendix|ancestor::article|ancestor::bibliography|ancestor::book|
                                       
ancestor::chapter|ancestor::glossary|ancestor::part|ancestor::preface|
                                       
ancestor::refentry|ancestor::reference|ancestor::refsect1|ancestor::refsect2|
                                       
ancestor::refsect3|ancestor::refsection|ancestor::refsynopsisdiv|
                                       
ancestor::sect1|ancestor::sect2|ancestor::sect3|ancestor::sect4|ancestor::sect5|
                                       
ancestor::section|ancestor::setindex|ancestor::set|ancestor::sidebar|ancestor::mediaobject)[&scope;]"/>
  

  <xsl:variable name="id">
    
<xsl:call-template name="object.id">
      
<xsl:with-param name="object" select="$target[position() = 
last()]"/>
    </xsl:call-template>
  
</xsl:variable>
  
  <fo:basic-link 
internal-destination="{$id}"
                 
xsl:use-attribute-sets="index.page.number.properties">
    
<fo:page-number-citation ref-id="{$id}"/>
  
</fo:basic-link>
</xsl:template>

 

 

 

Bob Stayton
Sagehill Enterprises


 

 

----- Original Message ----- 

From: "Scott Hudson" <>

To: "Bob Stayton" <>

Cc: "Hudson, Scott" <>; "John Brown" <>; 
<>

Sent: Tuesday, September 30, 2008 4:07 
PM

Subject: Re: [docbook-apps] Incorrect page numbers 
in index for indexterms within mediaobjects?

> Thanks, Bob.
> 
> Unfortunately, these are all still 
resulting in the same page numbers in 
> the index. I also tried with 
Antenna House, and have the same result.
> 
> --Scott
> 

> Bob Stayton wrote:
>> Hi Scott,
>> Well, looking at 
the template matching mediaobject in fo/graphics.xsl, the
>> content of 
its objectinfo element is not processed, so no inline markers are
>> 
laid down for those indexterms.  The indexterms are found during the 
global
>> sweep of indexterms to build the index, but  there will 
be no target for
>> those index entries to link to in the body of the 
document.
>> 
>> This customization of the mediaobject 
template works with XEP.  I can't get
>> PDF images to work with 
FOP 0.95 at all, so I can't say if it works for
>> that.  In this 
customization, I added a keep-together property for the
>> container 
block, and I added an apply-templates to the indexterms so their
>> 
markers will be included in the block container.
>> 
>> 

>> <xsl:template match="mediaobject|mediaobjectco">
>> 

>>   <xsl:variable name="olist" 
select="imageobject|imageobjectco
>>                      
|videoobject|audioobject
>>                      
|textobject"/>
>> 
>>   <xsl:variable 
name="object.index">
>>     
<xsl:call-template 
name="select.mediaobject.index">
>>       
<xsl:with-param name="olist" 
select="$olist"/>
>>       
<xsl:with-param name="count" 
select="1"/>
>>     
</xsl:call-template>
>>   
</xsl:variable>
>> 
>>   <xsl:variable 
name="object" select="$olist[position() = $object.index]"/>
>> 

>>   <xsl:variable 
name="align">
>>     <xsl:value-of 
select="$object/descendant::imagedata[@align][1]/@align"/>
>>   
</xsl:variable>
>> 
>>   <xsl:variable 
name="id">
>>     <xsl:call-template 
name="object.id"/>
>>   </xsl:variable>
>> 

>>   <fo:block id="{$id}" 
keep-together.within-column="always">
>>     
<xsl:if test="$align != '' 
">
>>       <xsl:attribute 
name="text-align">
>>         
<xsl:value-of 
select="$align"/>
>>       
</xsl:attribute>
>>     
</xsl:if>
>> 
>>     
<xsl:apply-templates 
select="objectinfo/indexterm"/>
>>     
<xsl:apply-templates 
select="$object"/>
>>     
<xsl:apply-templates select="caption"/>
>>   
</fo:block>
>> </xsl:template>
>> 
>> Bob 
Stayton
>> Sagehill Enterprises
>> 
>> 

>> 
>> ----- Original Message -----
>> From: "Scott 
Hudson" <>
>> To: "Bob Stayton" <>
>> Cc: 
"Hudson, Scott" <>; "John Brown"
>> <>; 
<>
>> Sent: Tuesday, September 30, 2008 2:44 PM
>> 
Subject: Re: [docbook-apps] Incorrect page numbers in index for 
indexterms
>> within mediaobjects?
>> 
>> 

>>> Hi Bob,
>>>
>>> oddly enough, when I 
turn the xep.extensions on, I get that same set of
>>> errors. If I 
process the file with fop1.extensions on and xep.extensions
>>> off, 
the XEP produces the file and the index entries all pointing to 
the
>>> title page of the chapter...
>>>
>>> 
If I process using FOP, I get the index as well, but the PDFs 
aren't
>>> rendered on the actual 
pages.
>>>
>>> --Scott
>>>
>>> 
Bob Stayton wrote:
>>>> Hi Scott,
>>>> I tried 
processing your chapter, and XEP 
reports:
>>>>
>>>> [error] no entries for index 
key 'TEST'
>>>> [error] no entries for index key 
'TEST2'
>>>> [error] no entries for index key 
'TEST3'
>>>>
>>>> and there are no page numbers in 
the index.  Did you do some
>>>> 
customization
>>>> regarding indexterms inside objectinfo?  
I'm not getting any index
>>>> markers
>>>> at all 
for those indexterms.
>>>>
>>>> Bob 
Stayton
>>>> Sagehill Enterprises
>>>> 
>>>>
>>>>
>>>> ----- Original 
Message -----
>>>> From: "Scott Hudson" <>
>>>> To: "Scott Hudson" <>
>>>> Cc: "John Brown" <>;
>>>> <>
>>>> Sent: Tuesday, September 30, 2008 1:23 
PM
>>>> Subject: [docbook-apps] Incorrect page numbers in index 
for indexterms
>>>> within 
mediaobjects?
>>>>
>>>>
>>>>> 
Folks,
>>>>>
>>>>> Now that I can include 
external pages in my document, I want to be able
>>>>> 
to
>>>>> add indexterms to them. When I generate the index, 
however, the page
>>>>> numbers aren't quite right. These 
should each end up on a separate page.
>>>>> Instead, I 
get:
>>>>> T
>>>>> TEST, 144, 
144
>>>>> TEST2, 144
>>>>> TEST3, 
144
>>>>>
>>>>> Here's my 
source:
>>>>> 
<chapter>
>>>>>          
<title>Case 
Study</title>
>>>>>          
<mediaobject>
>>>>>
>>>>> 
<objectinfo><indexterm><primary>TEST</primary></indexterm></objectinfo>
>>>>>              
<imageobject>
>>>>>                  
<imagedata fileref="casestudy_001.pdf" scalefit="1"
>>>>> 
width="100%" contentdepth="100%" 
format="PDF"/>
>>>>>              
</imageobject>
>>>>>          
</mediaobject>
>>>>>          
<para/>
>>>>>          
<mediaobject>
>>>>>
>>>>> 
<objectinfo><indexterm><primary>TEST2</primary></indexterm></objectinfo>
>>>>>              
<imageobject>
>>>>>                  
<imagedata fileref="casestudy_002.pdf" scalefit="1"
>>>>> 
width="100%" contentdepth="100%" 
format="PDF"/>
>>>>>              
</imageobject>
>>>>>          
</mediaobject>
>>>>>          
<para/>
>>>>>          
<mediaobject>
>>>>>
>>>>> 
<objectinfo><indexterm><primary>TEST3</primary></indexterm></objectinfo>
>>>>>              
<imageobject>
>>>>>                  
<imagedata fileref="casestudy_003.pdf" scalefit="1"
>>>>> 
width="100%" contentdepth="100%" 
format="PDF"/>
>>>>>              
</imageobject>
>>>>>          
</mediaobject>
>>>>>          
<para/>
>>>>>          
<mediaobject>
>>>>>
>>>>> 
<objectinfo><indexterm><primary>TEST</primary></indexterm></objectinfo>
>>>>>              
<imageobject>
>>>>>                  
<imagedata fileref="casestudy_004.pdf" scalefit="1"
>>>>> 
width="100%" contentdepth="100%" 
format="PDF"/>
>>>>>              
</imageobject>
>>>>>          
</mediaobject>
>>>>>      
</chapter>
>>>>>
>>>>> 
Ideas?
>>>>>
>>>>> 
Thanks,
>>>>>
>>>>> 
--Scott
>>>>>
>>>>> Scott Hudson 
wrote:
>>>>>> Thanks, John! I had to add an additional 
template to contain the
>>>>>> chapter, but otherwise works 
like a 
charm!
>>>>>>
>>>>>>      
<xsl:template 
match="chapter[@role='external-doc']">
>>>>>>          
<xsl:apply-imports 
/>
>>>>>>      
</xsl:template>
>>>>>>
>>>>>>      
<xsl:template 
match="chapter[@role='external-doc']/mediaobject">
>>>>>>          
<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format"
>>>>>> 
font-size="0"
>>>>>>              
line-height="0" 
break-before="page"
>>>>>>              
break-after="page"   start-indent="0" 
end-indent="0">
>>>>>>              
<xsl:apply-imports/>
>>>>>>          
</fo:block>
>>>>>>      
</xsl:template>
>>>>>>
>>>>>> 
Best regards,
>>>>>>
>>>>>> 
--Scott
>>>>>>
>>>>>>
>>>>>> 
John Brown wrote:
>>>>>>> Scott Hudson <scott.hudson 
<at> flatironssolutions.com> 
writes:
>>>>>>>
>>>>>>>> John 
Brown and Jirka Kosek both had good suggestions to split 
the
>>>>>>>> case
>>>>>>>> 
study into individual pages using pdftk and then use 
mediaobject.
>>>>>>>>
>>>>>>>> 
This approach seems to work pretty well, although the generated 
index
>>>>>>>> entries don't seem to point to the 
same page where the image is
>>>>>>>> 
rendered
>>>>>>>> (pretty close, 
though).
>>>>>>>>
>>>>>>> 
Never used indexterm, so I have no 
idea.
>>>>>>>
>>>>>>> <! -- 
Docbook code snipped 
-->
>>>>>>>
>>>>>>>> The 
biggest problem I'm having now is that the image doesn't 
appear
>>>>>>>> 
to
>>>>>>>> scale the entire width of the page. I'm 
using XEP, but FOP 0.95 does
>>>>>>>> 
the
>>>>>>>> same (or 
worse).
>>>>>>>>
>>>>>>>> 
What am I missing? I've tried width="100%" but that also errors. 
I've
>>>>>>>> also tried setting the 
default.image.width param, but that doesn't
>>>>>>>> 
seem
>>>>>>>> to work 
either.
>>>>>>>>
>>>>>>>> 
Any 
ideas?
>>>>>>>>
>>>>>>>> 
Thanks and best 
regards,
>>>>>>>>
>>>>>>>> 
--Scott
>>>>>>> DocBook is making the image fit within 
the margins. The answer is
>>>>>>> to define custom page 
masters with left and right margins = 0.
>>>>>>> Maybe 
you will also want to suppress the normal DocBook 
headers
>>>>>>> and footers with titles and page 
numbers.
>>>>>>>
>>>>>>> The 
following code allows you to write
>>>>>>> <appendix 
role='external-doc'>
>>>>>>>   
<mediaobject>
>>>>>>>     
...
>>>>>>>   
</mediaobject>
>>>>>>>   
<mediaobject>
>>>>>>>     
...
>>>>>>>   
</mediaobject>
>>>>>>>   <!-- etc. 
-->
>>>>>>> 
</appendix>
>>>>>>>
>>>>>>> 
If your external page is the same size as your DocBook page, it 
will
>>>>>>> take up the entire 
page.
>>>>>>>
>>>>>>> 
<xsl:template 
name="user.pagemasters">
>>>>>>>   
<fo:simple-page-master 
master-name="back-odd-body-only"
>>>>>>>                            
page-width="{$page.width}"
>>>>>>>                            
page-height="{$page.height}"
>>>>>>>                            
margin-top="0"
>>>>>>>                            
margin-bottom="0"
>>>>>>>                            
margin-left="0"
>>>>>>>                            
margin-right="0">
>>>>>>>       
<xsl:if test="$axf.extensions != 
0">
>>>>>>>         
<xsl:call-template 
name="axf-page-master-properties">
>>>>>>>           
<xsl:with-param
>>>>>>> 
name="page.master">back-odd-body-only</xsl:with-param>
>>>>>>>         
</xsl:call-template>
>>>>>>>       
</xsl:if>
>>>>>>>       
<fo:region-body 
margin-bottom="0"
>>>>>>>                       
margin-top="0"
>>>>>>>                       
column-gap="{$column.gap.back}"
>>>>>>>                       
column-count="{$column.count.back}">
>>>>>>>       
</fo:region-body>
>>>>>>>
>>>>>>>     
</fo:simple-page-master>
>>>>>>>
>>>>>>>     
<fo:simple-page-master 
master-name="back-even-body-only"
>>>>>>>                            
page-width="{$page.width}"
>>>>>>>                            
page-height="{$page.height}"
>>>>>>>                            
margin-top="0"
>>>>>>>                            
margin-bottom="0"
>>>>>>>                            
margin-left="0"
>>>>>>>                            
margin-right="0">
>>>>>>>       
<xsl:if test="$axf.extensions != 
0">
>>>>>>>         
<xsl:call-template 
name="axf-page-master-properties">
>>>>>>>           
<xsl:with-param
>>>>>>> 
name="page.master">back-even-body-only</xsl:with-param>
>>>>>>>         
</xsl:call-template>
>>>>>>>       
</xsl:if>
>>>>>>>       
<fo:region-body 
margin-bottom="0"
>>>>>>>                       
margin-top="0"
>>>>>>>                       
column-gap="{$column.gap.back}"
>>>>>>>                       
column-count="{$column.count.back}">
>>>>>>>       
</fo:region-body>
>>>>>>>     
</fo:simple-page-master>
>>>>>>>
>>>>>>>     
<fo:page-sequence-master 
master-name="back-body-only">
>>>>>>>       
<fo:repeatable-page-master-alternatives>
>>>>>>>         
<fo:conditional-page-master-reference 
master-reference="blank"
>>>>>>>
>>>>>>> 
blank-or-not-blank="blank"/>
>>>>>>>         
<fo:conditional-page-master-reference
>>>>>>> 
master-reference="back-first"
>>>>>>>                                               
page-position="first"/>
>>>>>>>         
<fo:conditional-page-master-reference
>>>>>>> 
master-reference="back-odd-body-only"
>>>>>>>                                               
odd-or-even="odd"/>
>>>>>>>         
<fo:conditional-page-master-reference 
odd-or-even="even">
>>>>>>>           
<xsl:attribute 
name="master-reference">
>>>>>>>             
<xsl:choose>
>>>>>>>               
<xsl:when test="$double.sided
>>>>>>> 
!=0">back-even-body-only</xsl:when>
>>>>>>>               
<xsl:otherwise>back-odd-body-only</xsl:otherwise>
>>>>>>>             
</xsl:choose>
>>>>>>>           
</xsl:attribute>
>>>>>>>         
</fo:conditional-page-master-reference>
>>>>>>>       
</fo:repeatable-page-master-alternatives>
>>>>>>>     
</fo:page-sequence-master>
>>>>>>>
>>>>>>>   
</xsl:template>
>>>>>>>
>>>>>>> 
<xsl:template 
name="select.user.pagemaster">
>>>>>>>   
<xsl:param name="element"/>
>>>>>>>   
<xsl:param name="pageclass"/>
>>>>>>>   
<xsl:param 
name="default-pagemaster"/>
>>>>>>>
>>>>>>>   
<!-- Return my customized title page master name if for 
titlepage,
>>>>>>>        
otherwise return the default 
-->
>>>>>>>
>>>>>>>   
<xsl:choose>
>>>>>>>     
<xsl:when test="@role = 
'external-doc'">
>>>>>>>       
<xsl:value-of select="'back-body-only'" 
/>
>>>>>>>     
</xsl:when>
>>>>>>>     
<xsl:otherwise>
>>>>>>>       
<xsl:value-of 
select="$default-pagemaster"/>
>>>>>>>     
</xsl:otherwise>
>>>>>>>   
</xsl:choose>
>>>>>>>   
</xsl:template>
>>>>>>>
>>>>>>>   
<xsl:template
>>>>>>> 
match="d:appendix[@role='external-doc']/d:mediaobject">
>>>>>>>     
<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format"
>>>>>>> 
font-size="0"
>>>>>>> line-height="0" 
break-before="page"
>>>>>>>               
break-after="page"   start-indent="0" 
end-indent="0">
>>>>>>>       
<xsl:apply-imports/>
>>>>>>>     
</fo:block>
>>>>>>>   
</xsl:template>
>>>>>>>
>>>>>>> 
I am not sure if the back-body-even-only and 
back-body-odd-only
>>>>>>> page masteres are strictly 
necessary.
>>>>>>>
>>>>>>> See 
the following thread:
>>>>>>> http://thread.gmane.org/gmane.text.docbook.apps/19707
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> 
---------------------------------------------------------------------
>>>>>>> 
To unsubscribe, e-mail: 
>>>>>>> For additional commands, 
e-mail:
>>>>>>> 
>>>>>>>
>>>>>>>
>>>>>> 
---------------------------------------------------------------------
>>>>>> 
To unsubscribe, e-mail: 
>>>>>> For additional commands, e-mail: 

>>>>>>
>>>>>>
>>>>> 
---------------------------------------------------------------------
>>>>> 
To unsubscribe, e-mail: 
>>>>> For additional commands, e-mail: 

>>>>>
>>>>>
>>>>>
>>>>
>>>
>>> 
---------------------------------------------------------------------
>>> 
To unsubscribe, e-mail: 
>>> For additional commands, e-mail: 
>>>
>>>
>>>
>> 
>> 

> 
> 
> 
---------------------------------------------------------------------
> To 
unsubscribe, e-mail: 
> For additional commands, e-mail: 
> 
> 
>
Next in thread → Next in month →