CSTUG

Stylesheet

<xsl:stylesheet version="1.0">

<!-- This stylesheet expands acronyms. It should be imported or included into other stylesheets. The acronyms are expanded in one of three modes according to the value of the "acromode" variable. Its value should be "TeX" or "html" or "text". Alternatively you can use the template in one of the modes or call the template by name. -->
<xsl:key name="acronym" match="//c:acronym" use="@id"/>
<!-- Generic template, mode is taken from global variable $acromode -->
<xsl:template match="c:acro"> <xsl:choose> <xsl:when test="$acromode = 'html'"> <xsl:call-template name="acro-html"/> </xsl:when> <xsl:when test="$acromode = 'TeX'"> <xsl:call-template name="acro-TeX"/> </xsl:when> <xsl:when test="$acromode = 'text'"> <xsl:call-template name="acro-text"/> </xsl:when> <xsl:otherwise> <xsl:message> Error: $acromode must be one of "html" or "TeX" or "text". </xsl:message> </xsl:otherwise> </xsl:choose> </xsl:template>
<!-- text mode -->
<xsl:template name="acro-text" match="c:acro" mode="text"> <xsl:variable name="id"><xsl:value-of select="."/></xsl:variable> <xsl:for-each select="$acronymlist"> <xsl:variable name="acro" select="key('acronym', $id)"/> <xsl:choose> <xsl:when test="$acro"> <xsl:value-of select="$acro/c:text"/> </xsl:when> <xsl:otherwise> <xsl:text><</xsl:text><xsl:value-of select="$id"/><xsl:text>></xsl:text> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:template>
<!-- TeX mode -->
<xsl:template name="acro-TeX" match="c:acro" mode="TeX" priority="1"> <xsl:variable name="id"><xsl:value-of select="."/></xsl:variable> <xsl:for-each select="$acronymlist"> <xsl:variable name="acro" select="key('acronym', $id)"/> <xsl:choose> <xsl:when test="$acro"> <xsl:apply-templates select="$acro/c:TeX" mode="TeX"/> </xsl:when> <xsl:otherwise> <xsl:text>{{</xsl:text><xsl:value-of select="$id"/><xsl:text>}}</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:template>
<!-- html mode -->
<xsl:template name="acro-html" match="c:acro" mode="html" priority="1"> <xsl:variable name="id"><xsl:value-of select="."/></xsl:variable> <xsl:for-each select="$acronymlist"> <xsl:variable name="acro" select="key('acronym', $id)"/> <xsl:choose> <xsl:when test="$acro"> <xsl:apply-templates select="$acro/c:html" mode="html"/> </xsl:when> <xsl:otherwise> <font color="red"><u><xsl:value-of select="$id"/></u></font> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:template>
<!-- All other elements below c:acronym/c:html are just copied -->
<xsl:template match="c:acronym/c:html//*" mode="html" priority="0.5"> <xsl:copy> <xsl:apply-templates select="@*" mode="html"/> <xsl:apply-templates mode="html"/> </xsl:copy> </xsl:template>
<!-- Attributes in mode html, mode is used for preventing possible conflicts -->
<xsl:template match="@*" mode="html"> <xsl:copy/> </xsl:template>
<!-- Text nodes in both modes are copied without normalizing the spaces -->
<xsl:template match="text()" mode="html"> <xsl:value-of select="."/> </xsl:template> <xsl:template match="text()" mode="TeX"> <xsl:value-of select="."/> </xsl:template> </xsl:stylesheet>

acro.xsl