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] Collecting glossentries in glossary database


Finally I got something working in HTML and I hope, that there are only 
some small changes required, to get it working with FO too (I think 
Jirka Kosek was the last one working on glossary.xsl, perhaps he can 
point out, what is needed).

I still rely on glossterm/@linkend, the glossary can be (x)included in 
the document further on, so I have no problems with validating the 
document. The only problem remaining is with glossseealso. Either it can 
happen that relevant glossentries are missing, because they didn't 
appear in the document, but were referenced by a glossseealso, or too 
many of them appear in the result, because I gather all those, that were 
referenced by otherterm too. For the moment I work with the latter - I 
declared the following key:

    <xsl:key name="referenced-glossentries" match="glossterm/@linkend | 
glossseealso/@otherterm" use="."/>

I use this key in the copy process of "glossary", to get the 
intersection between the referenced one and the glossary itself. The 
copy process is also used for sorting. The result tree may contain empty 
glossdivs, but the rest of glossary.xsl pays already attention to that 
(so I don't need to bother about it :-)).

<xsl:template match="@* | node()" mode="collect-and-sort">
  <xsl:copy>
    <xsl:apply-templates select="@*" mode="collect-and-sort"/>
    <!-- don't apply copy to glossentry, it gets extra "care" -->
    <xsl:apply-templates select="node()[not(name()='glossentry')]" 
mode="collect-and-sort"/>
    <!-- only use item of glossentry if it was at least referenced once-->
    <xsl:for-each select="glossentry[key('referenced-glossentries',@id)]">
      <xsl:sort select="@sortas"/>
      <!-- acronym = your gusto!!! -->
      <xsl:sort select="acronym"/>
      <xsl:sort select="glossterm"/>
        <!-- (re)generate glossentry element-->
      <xsl:element name="glossentry">
        <!-- and copy all of what it contained -->
        <xsl:copy-of select="@*"/>
        <xsl:copy-of select="*"/>
      </xsl:element>
    </xsl:for-each>
  </xsl:copy>
</xsl:template>

The copying template is called by a small template that triggers on an 
extra role attribute with the content "collect-and-sort" in the style of 
role="auto" of the existing "Glossary Collection" templates. I use a 
template name "make-glossary" (as in fo stylesheet) and extended the 
existing (normal) glossary template in glossary.xsl by this name.

<xsl:template match="glossary[@role='collect-and-sort']"  priority="2" >
  <xsl:variable name="collected.glossary">
    <xsl:apply-templates select="self::glossary" mode="collect-and-sort" />
  </xsl:variable>

  <xsl:for-each select="exsl:node-set($collected.glossary)/glossary">
    <xsl:call-template name="make-glossary"/>
  </xsl:for-each>
</xsl:template>

I tested all this first in a driver stylesheet, then I checked out, how 
it would fit into the official stylesheets. I copied the two templates 
into common.xsl (they do not generate output dependent markup) and just 
extended the existing <xsl:template match="glossary"> with 
'name="make-glossary"' - and it worked (in HTML). So actually, their 
would only be one line to be changed.

One can imagine some further enhancements:

1) among role="collect-and-sort", collecting AND sorting should be 
controllable via 2 separate parameters

2) the glossseealso problem could bee solved by a two pass copy process

Feedback is welcome! I would be glad to hear, if this solution is 
working in all circumstances, maybe it can be part of the normal 
stylesheet distro.

Regards,
Georges

PS

I can't tell, if my solution is generally working. Eg. as I was looking 
into the stylesheets, I was astonished, that @id is the only attribute 
used for key access so far, at least it was the only one I found. Maybe 
keys are problematic with DocBook stylesheets?

> Perhaps I'll try to figure out a small stylesheet for collecting the 
> effectively used glossterms. A copy process on the glossary database, 
> that kicks out all glossentries, that weren't referenced - shouldn't 
> be that difficult.
>
> BTW, a small script, that sorts the glossentries in a glossary 
> (respecting glossdiv,...), would be welcome as well, or I have to 
> write it myself. 








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