Page 1 of 1

Sort glossary in alphabetical order

Posted: Wed Apr 04, 2018 2:44 pm
by anna_craneo
I have created ditamap for my glossterms

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd">
<map id="glossary">
<title>A Glossary of Terms used in <ph keyref="product"/></title>
<topicmeta>
<shortdesc>Definitions for terms used in <ph keyref="product"/></shortdesc>
<data name="wh-menu">
<data name="hide" value="no"/>
</data>
</topicmeta>
<glossref href="../glossary/risk-score.dita" print="yes" toc="no" product="platform"
keys="glossentry-risk-score"/>
<glossref href="../glossary/case.dita" keys="glossentry-case" print="yes" toc="no"
product="platform"/>
<glossref href="../glossary/ME-group.dita" print="yes" toc="no" product="platform"
keys="glossentry-me-group"/>
<glossref href="../glossary/owner.dita" print="yes" toc="no" product="platform"
keys="glossentry-owner"/>
</map>
Now I would like to sort refs in alphabetical order. I have found this post, but I do not use bookmap.

I'm not very strong in XSLT, so I would really appreciate any help.

Re: Sort glossary in alphabetical order

Posted: Wed Apr 11, 2018 2:45 pm
by Radu
Hi,

Maybe in order to use the XSLT stylesheet I proposed on that blog post you could add a <topicgroup> with a certain "id='glossarylistgroup'" attribute to surround all your topicrefs to glossary entries (this will not change how the publishing looks like).
And then in the XSLT stylesheet instead of having the XSLT template match the "glossarylist" have it match that topicgroup like:

Code: Select all

<xsl:template match="topicgroup[@id='glossarylistgroup']">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:for-each select="*" >
<xsl:sort select="document(@href, .)/*/glossterm/text()"/>
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:copy>
</xsl:template>
Regards,
Radu

Re: Sort glossary in alphabetical order

Posted: Thu Dec 05, 2019 11:29 am
by B-E-N
I am also trying to sort glossary terms in alphabetical order in our numerous target languages.

We are using ditamaps instead of bookmaps so the initial code from the blog post obviously doesn't work.

I've added the <topicgroup> element then and used your code provided in this thread. Without success.

Is this supposed to work with our glossary term structure?

This is how our glossary term topics look like:

Code: Select all

<glossentry xml:lang="de-DE" id="example_g">
    <glossterm>Beispiel</glossterm>
    <glossdef>
        <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p>
    </glossdef>
    <prolog>
        <author>b-e-n</author>
        <critdates>
            <created date="2018-07-03"/>
            <revised modified="2019-11-08"/>
        </critdates>
    </prolog>
</glossentry>
When I apply the refactoring method you've explained it does not have any effect on the ditamap. Do I have to make a special selection or change the code somewhere?

I am using the XSL you've provided in this thread.

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    <xsl:template match="node() | @*">
        <xsl:copy>
            <xsl:apply-templates select="node() | @*"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="glossarylist">
        <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:for-each select="*" >
                <xsl:sort select="document(@href, .)/*/glossterm/text()"/>
                <xsl:apply-templates select="."/>
            </xsl:for-each>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Re: Sort glossary in alphabetical order

Posted: Thu Dec 05, 2019 12:10 pm
by Radu
Hi,

If the DITA Map has a structure like this:

Code: Select all

  <topicgroup id='glossarylistgroup'>
    <topicref href="concepts/glossaryGenus.dita"
      keys="genus" print="yes"/>
    <topicref href="concepts/glossaryPollination.dita"
      keys="pollination" print="yes"/>
  </topicgroup>
then an XSLT refactoring operation looking like this should sort it:

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    <xsl:template match="node() | @*">
        <xsl:copy>
            <xsl:apply-templates select="node() | @*"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="topicgroup[@id='glossarylistgroup']">
        <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:for-each select="*" >
                <xsl:sort select="document(@href, .)/*/glossterm/text()"/>
                <xsl:apply-templates select="."/>
            </xsl:for-each>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>
Regards,
Radu

Re: Sort glossary in alphabetical order

Posted: Thu Dec 05, 2019 4:17 pm
by B-E-N
This works perfectly. Thank you!

Re: Sort glossary in alphabetical order

Posted: Thu Dec 05, 2019 4:55 pm
by B-E-N
One addition:

The sorting was case sensitive. So the resulting order was like this:
A
B
a


Instead of:
A
a
B


I've then added <xsl:choose> to your code to add the "lang" attribute when needed. This sorts the languages as required.

Code: Select all

            <xsl:when test="/map/@xml:lang='de-DE'">
                <xsl:copy>
                    <xsl:apply-templates select="@*"/>
                    <xsl:for-each select="*" >
                        <xsl:sort select="document(@href, .)/*/glossterm/text()" lang="de"/>
                        <xsl:apply-templates select="."/>
                    </xsl:for-each>
                </xsl:copy>
            </xsl:when>
This seems to work now as intended. Thanks again.

Re: Sort glossary in alphabetical order

Posted: Mon Dec 09, 2019 9:31 am
by Radu
Hi,

Thanks, I will also try to update the code sample on the blog post to reflect your idea of taking the xml:lang into account.

Regards,
Radu

Re: Sort glossary in alphabetical order

Posted: Mon Dec 09, 2019 1:44 pm
by B-E-N
Icing on the cake would be if I could integrate the refactoring into a transformation scenario.

To automatize the WebHelp glossary term sorting. This way the authors would not have to memorize another step before publishing.

Re: Sort glossary in alphabetical order

Posted: Mon Dec 09, 2019 2:48 pm
by Radu
Hi,

Right, handling this at publishing time would be more interesting although it may also help at editing time to have the glossentries sorted in the map.
We have an internal issue to add sorting for glossary entries in our WebHelp Responsive output, if we manage to implement it I will update this forum thread.
We already have plugin extension points which can get called when various parts of our WebHelp responsive output is built:

https://www.oxygenxml.com/doc/versions/ ... mport.html

For example one of those extension points allows adding a custom XSLT stylesheet when the WebHelp table of contents is build com.oxygenxml.webhelp.xsl.createTocXML.
So doing something like this in the publishing output is not impossible, maybe you can also ask around on the DITA Users List, see if maybe others have already done this.

Regards,
Radu

Re: Sort glossary in alphabetical order

Posted: Tue Dec 31, 2019 8:16 pm
by essamnagy
We are using ditamaps instead of bookmaps so the initial code from the blog post obviously doesn't work.

Re: Sort glossary in alphabetical order

Posted: Mon Jan 06, 2020 1:41 pm
by Radu
Hi,

An update of the blog post can be found on our new Oxygen XML Blog platform hosted by Netlify:

https://oxygenxmlblog.netlify.com/topic ... tries.html

In that updated XSLT the template matches:

Code: Select all

 <xsl:template match="glossarylist | topicgroup[@outputclass='glossarylist']">
meaning that you can have a <topicgroup> with the outputclass='glossarylist' attribute set on it which in turn would contain inside all the topicrefs pointing to the glossentries.

Regards,
Radu