A proposal for glossary stylesheet processing

reinierk
Posts: 36
Location: Rotterdam, the Netherlands

A proposal for glossary stylesheet processing

Mon Jan 21, 2013 1:25 pm

Below are some extensions I made to the glossary processing to get better and nicer layout for glossary entries

Code: Select all

<!-- Glossary group headings -->
    <xsl:template
        match="ot-placeholder:glossarylist//*[contains(@class, ' glossgroup/glossgroup ')]">
       <!-- <fo:block xsl:use-attribute-sets="__glossary__group-head">
            <xsl:call-template name="commonattributes"/>-->
            <xsl:apply-templates select="*[contains(@class,' topic/title ')]"/>
      <!--  </fo:block>-->
    </xsl:template>
   
    <!-- Normal Glossary entry -->
    <xsl:template
        match="ot-placeholder:glossarylist//*[contains(@class, ' glossentry/glossentry ')]">
        <fo:block>
            <xsl:call-template name="commonattributes"/>
            <fo:block>
                <xsl:attribute name="id">
                    <xsl:call-template name="generate-toc-id"/>
                </xsl:attribute>
                <fo:block xsl:use-attribute-sets="__glossary__term">
                    <xsl:apply-templates
                        select="*[contains(@class, ' glossentry/glossterm ')]/node()"/>
                    <xsl:if
                        test="count(descendant-or-self::*[contains(@class, ' glossentry/glossAcronym ')]) gt 0">
                        <xsl:text> (</xsl:text>
                        <xsl:apply-templates
                            select="descendant-or-self::*[contains(@class, ' glossentry/glossAcronym ')][1]"/>
                        <xsl:text>)</xsl:text>
                    </xsl:if>
                </fo:block>
                <fo:block xsl:use-attribute-sets="__glossary__def">
                    <xsl:apply-templates
                        select="*[contains(@class, ' glossentry/glossdef ')]/node()"/>
                    <xsl:apply-templates select="*[contains(@class, ' glossentry/glossBody ')]"/>
                    <xsl:apply-templates select="*[contains(@class, ' topic/related-links ')]"/>
                </fo:block>
            </fo:block>
        </fo:block>
    </xsl:template>

    <xsl:template match="*[contains(@class, ' glossentry/glossBody ')]">
        <xsl:variable name="synonyms"
            select="descendant-or-self::*[contains(@class, ' glossentry/glossSynonym ')]/node()"/>
        <xsl:variable name="acronyms"
            select="descendant-or-self::*[contains(@class, ' glossentry/glossAcronym ')]/node()"/>
        <xsl:variable name="abbrevs"
            select="descendant-or-self::*[contains(@class, ' glossentry/glossAbbreviation ')]/node()"/>
        <xsl:if test="count($synonyms) gt 0">
            <fo:block xsl:use-attribute-sets="__glossary__synonyms">
                <fo:inline xsl:use-attribute-sets="__glossary__synonyms-label">
                    <xsl:call-template name="insertVariable">
                        <xsl:with-param name="theVariableID" select="'Synonyms'"/>
                    </xsl:call-template>
                </fo:inline>
                <xsl:for-each
                    select="descendant-or-self::*[contains(@class, ' glossentry/glossSynonym ')]">
                    <!--                <xsl:value-of select="string-join($abbrevs, ', ')"/>-->
                    <xsl:apply-templates select="."/>
                    <xsl:if test="position() lt last()">
                        <xsl:text>, </xsl:text>
                    </xsl:if>
                </xsl:for-each>
            </fo:block>
        </xsl:if>
        <xsl:if test="count($acronyms) gt 0">
            <fo:block xsl:use-attribute-sets="__glossary__acronyms">
                <fo:inline xsl:use-attribute-sets="__glossary__acronyms-label">
                    <xsl:call-template name="insertVariable">
                        <xsl:with-param name="theVariableID" select="'Acronyms'"/>
                    </xsl:call-template>
                </fo:inline>
                <xsl:value-of select="string-join($acronyms, ', ')"/>
            </fo:block>
        </xsl:if>
        <xsl:if test="count($abbrevs) gt 0">
            <fo:block xsl:use-attribute-sets="__glossary__abbrevs">
                <fo:inline xsl:use-attribute-sets="__glossary__abbrevs-label">
                    <xsl:call-template name="insertVariable">
                        <xsl:with-param name="theVariableID" select="'Abbrevs'"/>
                    </xsl:call-template>
                </fo:inline>
                <xsl:for-each
                    select="descendant-or-self::*[contains(@class, ' glossentry/glossAbbreviation ')]">
                    <!--                <xsl:value-of select="string-join($abbrevs, ', ')"/>-->
                    <xsl:apply-templates select="."/>
                    <xsl:if test="position() lt last()">
                        <xsl:text>, </xsl:text>
                    </xsl:if>
                </xsl:for-each>
            </fo:block>
        </xsl:if>
    </xsl:template>

    <xsl:template match="*[contains(@class, ' glossentry/glossSynonym ')]">
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="*[contains(@class, ' glossentry/glossAbbreviation ')]">
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="*[contains(@class, ' glossentry/glossAcronym ')]">
        <xsl:apply-templates/>
    </xsl:template>

These output stuff like:
Intel 64 (x86-64)
A 64-bit extension of IA-32, the 32-bit generation of the x86 instruction set. It supports vastly larger amounts of virtual memory and physical memory than is possible on IA-32, allowing programs to store larger amounts of data in memory. x86-64 also provides 64-bit general purpose registers and numerous other enhancements. The original specification was created by AMD, and has been implemented by AMD, Intel, VIA, and others. It is fully backwards compatible with 16-bit and 32-bit x86 code.
Synonyms: Intel 64
Acronyms: x86-64, x64, EM64T
Related Links
Intel Itanium architecture on page 227
Kind Regards,
Reinier Kleipool,
Course Materials editor,
Open Source Academy
http://www.OpenSourceAcademy.eu
susannecm
Posts: 60

Re: A proposal for glossary stylesheet processing

Mon Jan 21, 2013 1:31 pm

Thanks a lot for sharing this!
I am supposed to include synonyms in glossaries, so this could be very helpful.

Susanne
reinierk
Posts: 36
Location: Rotterdam, the Netherlands

Re: A proposal for glossary stylesheet processing

Mon Jan 21, 2013 1:36 pm

Forgot to include glossary-attrs.xsl:

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="2.0">
    <xsl:attribute-set name="__glossary__label">
        <xsl:attribute name="space-before">20pt</xsl:attribute>
        <xsl:attribute name="space-after">20pt</xsl:attribute>
        <xsl:attribute name="font-size">20pt</xsl:attribute>
        <xsl:attribute name="font-weight">bold</xsl:attribute>
    </xsl:attribute-set>
   
    <xsl:attribute-set name="__glossary__group-head">
       <!-- <xsl:attribute name="font-weight">bold</xsl:attribute>
        <xsl:attribute name="border-bottom">solid 0.5pt black</xsl:attribute>
        <xsl:attribute name="end-indent">4cm</xsl:attribute>
        <xsl:attribute name="space-before">10pt</xsl:attribute>-->
        <xsl:attribute name="span">all</xsl:attribute>
    </xsl:attribute-set>

    <xsl:attribute-set name="__glossary__term">
        <xsl:attribute name="font-weight">bold</xsl:attribute>
        <xsl:attribute name="space-before">3pt</xsl:attribute>
    </xsl:attribute-set>

    <xsl:attribute-set name="__glossary__def">
    </xsl:attribute-set>
   
    <xsl:attribute-set name="__glossary__abbrevs">
    </xsl:attribute-set>
   
    <xsl:attribute-set name="__glossary__abbrevs-label">
        <xsl:attribute name="font-weight">bold</xsl:attribute>
    </xsl:attribute-set>
   
    <xsl:attribute-set name="__glossary__acronyms">
    </xsl:attribute-set>
   
    <xsl:attribute-set name="__glossary__acronyms-label">
        <xsl:attribute name="font-weight">bold</xsl:attribute>
    </xsl:attribute-set>

    <xsl:attribute-set name="__glossary__synonyms">
    </xsl:attribute-set>
   
    <xsl:attribute-set name="__glossary__synonyms-label">
        <xsl:attribute name="font-weight">bold</xsl:attribute>
    </xsl:attribute-set>
</xsl:stylesheet>

Please also have a look at my post about abbreviated-form
Kind Regards,
Reinier Kleipool,
Course Materials editor,
Open Source Academy
http://www.OpenSourceAcademy.eu
Radu
Posts: 5878

Re: A proposal for glossary stylesheet processing

Mon Jan 21, 2013 1:36 pm

Hi Reinier,

If you want these changes to be included in future DITA OT distributions, maybe you should add an issue at:

https://github.com/dita-ot/dita-ot/issues

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Return to “DITA (Editing and Publishing DITA Content)”

Who is online

Users browsing this forum: juhopvx and 2 guests