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>


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 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 

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">

Here is the stylesheet:

------[ index.xsl ]------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
 <xsl:template match="/">
   <!-- DON'T cut and past this template to your customization layer -->
     <xsl:apply-templates mode="index-primary"/>

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

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

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

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

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

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";>

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.

  Thomas Schraitle

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