Expansion of acronyms: interesting XSLT hack
TL reported the need to provide mouseover title attributes expanding the acronyms in links such as "ODNB" and "MASL" in the biographies. Creating parameters holding the acronyms was easy, following our usual system for <xsl:param>
s created dynamically from the boilerplate.xml file, but the problem then was how to access those values dynamically. For instance, if the parameter name is $ODNB_expansion
, but all I know is that the text I want to expand is "ODNB", there's no way to dynamically construct the variable name based on the string.
The solution: following the definition of the parameters in the captions stylesheet, do this:
<xsl:variable name="acronymKeys"> <xsl:for-each select="document('')//xsl:param[ends-with(@name, '_expansion')]"> <hcmc:expansion key="{substring-before(@name, '_')}"><xsl:value-of select="text()"/></hcmc:expansion> </xsl:for-each> </xsl:variable>
This processes the contents of the target parameters into a key-value structure which can be used to look up the appropriate expansion. Neat.