OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

docbook-apps message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: Re: [docbook-apps] Selecting text styles for elements within <indexterm>


Thomas,
Thanks for pointing me in the right direction - with the addition of templates I've *almost* got the index looking as I need it. I do have a problem with secondary entries and "see" entries being repeated after a primary entry. The attached screenshot shows two typical instances where a "see" entry, and the last "secondary" entry that follows a primary entry, is repeated after the primary entry.

My customization is:

<xsl:template match="d:indexterm" mode="index-primary">
    <xsl:param name="scope" select="."/>
    <xsl:param name="role" select="''"/>
    <xsl:param name="type" select="''"/>
   
    <xsl:variable name="key" select="&primary;"/>
    <xsl:variable name="refs" select="key('primary', $key)[&scope;]"/>
   
    <xsl:variable name="term.separator">
      <xsl:call-template name="index.separator">
        <xsl:with-param name="key" select="'index.term.separator'"/>
      </xsl:call-template>
    </xsl:variable>
   
    <xsl:variable name="range.separator">
      <xsl:call-template name="index.separator">
        <xsl:with-param name="key" select="'index.range.separator'"/>
      </xsl:call-template>
    </xsl:variable>
   
    <xsl:variable name="number.separator">
      <xsl:call-template name="index.separator">
        <xsl:with-param name="key" select="'index.number.separator'"/>
      </xsl:call-template>
    </xsl:variable>
   
    <fo:block>
      <xsl:apply-templates mode="index-primary"/><!--OK here 2/9/12-->
      <xsl:if test="$axf.extensions != 0">
        <xsl:attribute name="axf:suppress-duplicate-page-number">true</xsl:attribute>
      </xsl:if>
...

And new templates for index entries:

<xsl:template match="d:primary" mode="index-primary">
    <fo:inline>
      <xsl:apply-templates mode="index-primary"/>
    </fo:inline>
  </xsl:template>

  <xsl:template match="d:literal" mode="index-primary">
    <fo:inline font-family="monospace">
      <xsl:apply-templates mode="index-primary"/>
    </fo:inline>
  </xsl:template>

  <xsl:template match="d:quote" mode="index-primary">
    <fo:inline>
      <xsl:call-template name="gentext.startquote"/>
      <xsl:apply-templates mode="index-primary"/>
      <xsl:call-template name="gentext.endquote"/>
    </fo:inline>
  </xsl:template>

  <xsl:template match="d:emphasis" mode="index-primary">
    <fo:inline font-style="italic">
      <xsl:apply-templates mode="index-primary"/>
    </fo:inline>
  </xsl:template>

I'll keep looking to find the logic as to why I'm getting secondary and see entries generated twice. I think it's to do with where I put the <xsl:apply-templates mode="index-primary"/> in the indexterm template.
Dave

On 01-09-12 7:40 PM, Thomas Schraitle wrote:
Hi,

Am Samstag, 1. September 2012, 17:42:03 schrieb Xmplar:
I have a customization for styling <emphasis>, <quote> and <literal>
elements that are contained in <primary> index elements.

Typical markup is:

<indexterm class="startofrange" xml:id="abstract">
<primary><literal>abstract</literal>element/tag</primary>
</indexterm>

In the autoindex, I only want to style the text contained within the
<literal> tags as font-family "monospace", but all of the text within
the <primary> element is styled as monospace.
And your primary (except literal) should be styled as serif or sans serif?

 
My customization in
<xsl:templatematch="d:indexterm"mode="index-primary"> is:

<xsl:choose>
 [...]
</xsl:choose>
XSLT doesn't work this way. You *could* write something as you did, but it is 
hard to maintain and not very readable. I would recommend to write more 
templates.

Templates is the way XSLT work. Templates deliver only a small part of the 
output tree. So one template could create a bold text whereas another one 
would creates the monospace text. To distinguish which produces which, use a 
XPath _expression_. 

 
As you can see, for d:primary/d:literal, I'm attempting to style only
d:literal as monospace, and for any text following that (within
d:primary) as normal text. So, I'm trying to separate text in
d:primary/d:literal from all other text within d:primary so I can apply
two types of font styles. The _expression_
"d:primary[not(child::d:literal)]" doesn't generate the text outside of
d:literal. Is there an XPath _expression_ to achieve this?
Sorry, but your code is too complicated. :) XSLT is different, it's NOT a 
procedural language (although some elements might think so). In almost all 
cases you write templates and the XSLT processor decides which one should be 
executed.  

Here is a small test case you can use to tweak it to your needs. It just focus 
on the indexterm, its children, but nothing else. Be aware, it doesn't create 
a working FO file. I've integrated only the essential parts, no DocBook 
customization etc. You need to cut the templates and past it to your 
customization layer.

Let's say, you have the following XML file (taken from your example above, 
added DocBook 5 namespace):

------[ index.xml ]------
<indexterm xmlns="http://docbook.org/ns/docbook"
  class="startofrange" xml:id="abstract">
 <primary><literal>abstract</literal>element/tag</primary>
</indexterm>
-------------------------

Here is the stylesheet:

------[ index.xsl ]------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:d="http://docbook.org/ns/docbook"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  exclude-result-prefixes="d">
  
 <xsl:template match="/">
   <!-- DON'T cut and past this template to your customization layer -->
   <fo:root>
     <xsl:apply-templates mode="index-primary"/>
   </fo:root>  
 </xsl:template>

 <xsl:template match="d:indexterm" mode="index-primary">
   <fo:block>
     <xsl:apply-templates mode="index-primary"/>
   </fo:block>
 </xsl:template>

 <xsl:template match="d:primary" mode="index-primary">
   <fo:inline><!-- font-family="serif" -->
     <xsl:apply-templates mode="index-primary"/>
   </fo:inline>
 </xsl:template>

 <xsl:template match="d:literal" mode="index-primary">
   <fo:inline font-family="monospace">
     <xsl:apply-templates mode="index-primary"/>
   </fo:inline>
 </xsl:template>

 <xsl:template match="d:quote" mode="index-primary">
   <fo:inline>
     <!--<xsl:call-template name="gentext.startquote"/>-->
     <xsl:text>"</xsl:text>
     <xsl:apply-templates mode="index-primary"/>
     <!--<xsl:call-template name="gentext.endquote"/>-->
     <xsl:text>"</xsl:text>
   </fo:inline>
 </xsl:template>

 <xsl:template match="d:emphasis" mode="index-primary">
   <fo:inline font-weight="bold">
     <xsl:apply-templates mode="index-primary"/>
   </fo:inline>
 </xsl:template>
</xsl:stylesheet>
-------------------------

Run xsltproc:

  $ xsltproc index.xsl index.xml

I get the following output (slightly modified to improve readability):

 <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
   <fo:block>
     <fo:inline><fo:inline 
      font-family="monospace">abstract</fo:inline>element/tag</fo:inline>
   </fo:block>
 </fo:root>

As you can see, only literal is marked up as monospace nothing else.

I don't know if this is what you wanted. Maybe I've misunderstood your 
intentions. Hope it helps.



--
Dave Gardiner
Xmplar
info@xmplar.biz
http://xmplar.biz
Mob. 0416 833 993

Attachment: idx-primary-styles.doc
Description: MS-Word document



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]