问题
Background: I'm writing a DocBook 5 document (and including in it some already-written text) with the intention of generating HTML from it. I would like to get the semantic markup correct from the beginning so I don't need to re-do it later, but the standard way does not seem to generate what I'm looking for, so I'm not sure if I should deviate from it or not, depending on what is possible with XSL.
Current setup: My glossary only has abbreviated items. It consists of glossentry
s each containing a full-spelling glossterm
and some non-zero amount of acronym
s and/or abbrev
s. I suppose it could all just be glossterm
s instead. It doesn't matter to me. Suppose for example I have this:
<glossentry xml:id="ff"><glossterm>Firefox</glossterm>
<acronym>FF</acronym>
<glossdef>
<para>The web browser made by Mozilla.</para>
</glossdef>
</glossentry>
Ideal
Suppose wherever I want to refer to Firefox, I put FF
in the text. Ideally, without any additional markup, wherever "FF" (case sensitive) appeared as a plain whole word in a para
graph (or title
, but not, for example, code
or programlisting
or inside a URL inside an attribute...) in my DocBook file, it would come out in HTML as the text "FF" but marked up as a link to the glossary entry, but not with the standard link CSS, and furthermore with a title
attribute having the value Firefox
. That way a reader can hover to get the acronym/abbreviation spelled out for them, and if that is insufficient, they can click to be taken to a fuller definition. Meanwhile I would style it black and underlined, so that they know this feature is there, but it doesn't distract one's attention like a normal link does, especially with how often it occurs in the text.
Main question: is such replacement of plaintext, markup-less terms even possible in XSL (without creating something like the Scunthorpe problem)? If so, can it do this for every acronym
or abbrev
found in the glossary, automatically?
I could not figure out how to do this directly, but that is still my goal. Meanwhile I've tried other things:
Approach 1
Set up a keyboard macro so I can type ff
and have that be transformed while I'm typing into <xref linkend="ff"/>
.
Pros:
- links to the glossary
- spells out the abbreviation
Cons:
- spells out the abbrevation (it would be nice to keep it short to read, not just short to type)...workaround: make the
acronym
into aglossterm
and put it first in theglossentry
(loss of semantics, but maybe that's OK here?) - links to the glossary (I would like it styled differently)...solution: CSS for
a.xref
- even with the above two worked around, the title comes out as
FFFirefox
instead of justFirefox
(and with others that have more than one synonym, the mashing-together continues)...solution: put an alternatexml:id
on your preferred acronym/abbrev, and then make the links in it refer to that id in theirendterm
attribute (as well as thelinkend
referring to the first id) - I have to remember to use the keyboard macro rather than just typing and letting the system do the work; any imported text then has to have text replacements done on it for each glossary entry
Approach 2
Using <xsl:param name="glossterm.auto.link" select="1"/>
and a keyboard macro to change FF
into <glossterm>FF</glossterm>
.
Pros:
- links to the glossary
Cons:
- spells out the abbrevation (it would be nice to keep it short to read, not just short to type)...workaround: make the
acronym
into aglossterm
and put it first in theglossentry
(loss of semantics, but maybe that's OK here?) - links to the glossary (I would like it styled differently)...solution: CSS for
.glossterm
- even with the above two worked around, no
title
attribute is given - I have to remember to use the keyboard macro rather than just typing and letting the system do the work; any imported text then has to have text replacements done on it for each glossary entry
Approach 1 so far seems better after the workarounds, but is there a way to achieve the ideal I outlined?
来源:https://stackoverflow.com/questions/28767936/markup-less-way-to-title-and-link-abbrevations-acronyms-to-glossary-entries