Using normalize-space to fix Oxygen "pretty print" spacing problems
This is a straightforward thing for people who know what they are doing. It is only a reminder to me, who didn’t.
The journals I publish using TEI XML use the tei:figDesc element to populate the alt and title attributes of html:img.
Until today, these results in very odd looking tool tips, where the text was spread all over the place, e.g.
The problem was being caused by the OxygenXML editor’s pretty-print feature and how that was being transformed to the title and alt attributes. I was extracting the contents of the element and putting them on the attribute, this was not stripping the white space, meaning that the text showed up with strange spacing and returns.
The solution was very easy: surround the content-call with normalize-space()
. Then everything worked fine. Here’s the relevant bit of XSLT:
<xsl:variable name="title">Click for full-sized image<xsl:if test="../tei:figDesc">
of <xsl:value-of select="../tei:figDesc"/></xsl:if></xsl:variable>
<a href="{@url}" style="text-decoration:none;border:0px;">
<img alt="{../tei:figDesc}" src="{@url}" title="{normalize-space($title)}">
<xsl:call-template name="attcore"/>
</img>