CSTUG

Stylesheet

<xsl:stylesheet version="1.0">

<!-- This stylesheet outputs the contents of the Bulletins of CSTUG into a LaTeX file. The resulting file cannot be processed as a standalone file. Instead it ia assumed that you write your own presentation style and include it into anothe document. It requires the standard package keyval and macro definitions from csbulacronym.sty which can be found at http://bulletin.cstug.cz/xml/ The stylesheet is generally used as: xslt -o output.tex source.xml stylesheet.xsl parameters * xslt represents your script for invoking the XSLT processor. The example is written having Saxon in mind but other XSLT processors can be used as well and their invocation should be similar. * output.tex is the output TeX file. * source.xml is the source XML document. You can retrieve information from: 1. the whole set of documents if you specify the source as http://bulletin.cstug.cz/xml/documents/toc.xml (or just toc.xml if you have a local copy) 2. all issues within a year, e.g. the sources for the year 2000 are contained in http://bulletin.cstug.cz/xml/documents/2000.xml 3. a single issue, e.g. the source for the issue 4 of year 2000 is http://bulletin.cstug.cz/xml/documents/2000~4.xml, the source for the triple issue 1-3 of year 2000 is http://bulletin.cstug.cz/xml/documents/2000~1-3.xml * The parameters are optional. There are two things which can be specified: 1. You should select output encoding because it is not specified in the stylesheet and the TeX file would thus be in UTF-8. Unless you have the latest encTeX (it is included in TeX Live as well as in tetex), you would choose either ISO-8859-2 or Windows-1250 or CP852 depending on your operating system. If you use Saxon v.8, you can do it on the command line e.g. by !encoding=ISO-8859-2. If your XSLT processor lacks such feature, you must create your own stylesheet which will first import one of the stylesheets, e.g. <xsl:import href="http://bulletin.cstug.cz/xml/documents/articles2.xsl"/> (for XSLT 2.0 processors) and then specify the output encoding, e.g. by <xsl:ouput encoding="ISO-88592"/>. 2. You can specify the language using the lang parameter. If you do not specify any langugae, the stylesheet will write titles, keywords and abstracts in all languages in the order as they appear in the XML file. If the lang parameter is given, the stylesheet will select the language with these preferences (information in some language may be missing): a) the requested language b) the language of the article c) Czech language d) the first item in the XML file The parameter must be 3-letter code according to ISO&nbsp;639-2. You can force the stylesheet to try to output the information in the language of the article by using a nonsense language code (the first condition will thus never be fulfilled). The following comments describe both the templates and the format of the output file. -->
<xsl:import href="index.xsl"/> <xsl:include href="acro.xsl"/> <xsl:include href="auth.xsl"/> <xsl:include href="kwd.xsl"/> <xsl:include href="xinclude.xsl"/> <xsl:param name="lang"/> <xsl:param name="IncludeOriginalTitle"/>
<!-- We implement output in the TeX mode only. -->
<xsl:variable name="acromode">TeX</xsl:variable> <xsl:output method="text" indent="no"/> <xsl:strip-space elements="*"/> <xsl:preserve-space elements="c:text"/>
<!-- The template for the root node just outputs the comment to the beginning of the TeX file. -->
<xsl:template match="/"> <xsl:text>% Requires csbulacronym.sty and keyval.sty </xsl:text> <xsl:if test="$lang != ''"> <xsl:value-of select="concat('% Requested language is ', $lang, ' ')"/> </xsl:if> <xsl:apply-templates/> </xsl:template>
<!-- Each issue will be presented as the CSTUGissue environment. Its argument contains a few strings in the form "key=value" which should be parsed using the keyval package. Mandatory values are: * year = the year of publication (numeric) * volume = the volume of the Bulletin, always equal to year - 1990 * number = the number of the issue within the year, may be non-numeric, e.g. 3-4 * href = URL of the WWW page with the contents The argument may optionally contain: * pdfref = URL of the PDF version if available * firstPage and lastPage = the first and last page of the issue Notice that pdfref may contain an underscore so that you should set \catcode`\_=12. You can reset it to its normal value at the beginning of the environment. -->
<xsl:template match="c:issue"> <xsl:text> \begin{CSTUGissue}{</xsl:text> <xsl:value-of select="concat('year=', substring-before(@id, '/'))"/> <xsl:value-of select="concat(',volume=', number(substring-before(@id, '/')) - 1990)"/> <xsl:value-of select="concat(',number=', @num)"/> <xsl:value-of select="concat(',href=', @href)"/> <xsl:if test="@pdfref"> <xsl:value-of select="concat(',pdfref=', @pdfref)"/> </xsl:if> <xsl:if test="@firstPage"> <xsl:value-of select="concat(',firstPage=', @firstPage)"/> </xsl:if> <xsl:if test="@lastPage"> <xsl:value-of select="concat(',lastPage=', @lastPage)"/> </xsl:if> <xsl:text>} </xsl:text> <xsl:apply-templates/> <xsl:text>\end{CSTUGissue} </xsl:text> </xsl:template>
<!-- The article information is enclosed within the CSTUGarticle environment with an argument which should also be parsed with the keyval package. The parameters are: * serial = the serial number of the article within the issue * lang = the language of the article according to ISO 639-2 * firstPage = the number of the first page * lastPage = the number of the last page (if available) In order to make the template more readable and easy to modify we leave handling of the parts of the contents to called templates. -->
<xsl:template match="c:article"> <xsl:text>\begin{CSTUGarticle}</xsl:text> <xsl:value-of select="concat('{serial=', @serial, ',lang=', @lang, ',firstPage=', @firstPage)"/> <xsl:if test="@lastPage"> <xsl:value-of select="concat(',lastPage=', @lastPage)"/> </xsl:if> <xsl:text>} </xsl:text> <xsl:text>\ActiveAmpersand </xsl:text> <xsl:call-template name="authors"/> <xsl:call-template name="title"/> <xsl:call-template name="keywords"/> <xsl:call-template name="abstract"/> <xsl:text>\end{CSTUGarticle} </xsl:text> </xsl:template>
<!-- Expand the author names (we use identifiers in the XML files). If there is no author, nothing will be written. If the article has atleast one author, they are output in the CSTUGauthors environment and each author is written as the argument of the \CSTUGauthor macro. The first name and surname are not separated. -->
<xsl:template name="authors"> <xsl:if test="count(c:author) > 0"> <xsl:text>\begin{CSTUGauthors} </xsl:text> <xsl:for-each select="c:author"> <xsl:text>\CSTUGauthor{</xsl:text> <xsl:apply-templates select="."/> <xsl:text>} </xsl:text> </xsl:for-each> <xsl:text>\end{CSTUGauthors} </xsl:text> </xsl:if> </xsl:template>
<!-- Here we write the abstract inside the CSTUGabstract environment the argument of which is the language code. If the "lang" parameter was not specified, all language variants are written inside the CSTUGabstractset environment. The order of the language variants is the same as in the XML file. You can store them and output them in a different order by your TeX macros. Remember that the abstracts may contain several paragraphs, do not forget to make your macros \long. Not all articles have abstracts and even Czech articles may contain English abstracts only. If no abstract is present, the environment will not appear in the output. The template always tries to output some abstract even in a different language according to the above mentioned algorithm. You should therefore always examine the argument. -->
<xsl:template name="abstract"> <xsl:if test="count(c:abstract) > 0"> <xsl:choose> <xsl:when test="$lang = ''"> <xsl:text>\begin{CSTUGabstractset} </xsl:text> <xsl:for-each select="c:abstract"> <xsl:text>\begin{CSTUGabstract}{</xsl:text> <xsl:value-of select="@lang"/> <xsl:text>} </xsl:text> <xsl:apply-templates/> <xsl:text> \end{CSTUGabstract} </xsl:text> </xsl:for-each> <xsl:text> \end{CSTUGabstractset} </xsl:text> </xsl:when> <xsl:otherwise> <xsl:text>\begin{CSTUGabstract}{</xsl:text> <xsl:choose> <xsl:when test="c:abstract[@lang=$lang]"> <xsl:value-of select="concat($lang, '} ')"/> <xsl:apply-templates select="c:abstract[@lang=$lang]"/> </xsl:when> <xsl:when test="c:abstract[@lang=../@lang]"> <xsl:value-of select="concat(@lang, '} ')"/> <xsl:apply-templates select="c:abstract[@lang=../@lang]"/> </xsl:when> <xsl:when test="c:abstract[@lang="cze"]"> <xsl:text>cze} </xsl:text> <xsl:apply-templates select="c:abstract[@lang="cze"]"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="concat(c:abstract[1]/@lang, '} ')"/> <xsl:apply-templates select="c:abstract[1]"/> </xsl:otherwise> </xsl:choose> <xsl:text> \end{CSTUGabstract} </xsl:text> </xsl:otherwise> </xsl:choose> </xsl:if> </xsl:template>
<!-- The title is written as the \CSTUGtitle macro with 2 parameters. The first parameter is the language code, the second parameter is the title. If all languages were requested by omitting the "lang" parameter, they are output in the CSTUGtitleset environment. Notice that the language of the title need not correspond to the language of the article, e.g. tha article with id 1993/1#9 is written in Czech but the only title was intentionally left in German. Similarly, this template always tries to output some title. You should therefore examine the first argument. -->
<xsl:template name="title"> <xsl:choose> <xsl:when test="$lang = ''"> <xsl:text>\begin{CSTUGtitleset} </xsl:text> <xsl:for-each select="c:title"> <xsl:text>\CSTUGtitle{</xsl:text> <xsl:value-of select="@lang"/> <xsl:text>}{</xsl:text> <xsl:apply-templates/> <xsl:text>} </xsl:text> </xsl:for-each> <xsl:text>\end{CSTUGtitleset} </xsl:text> </xsl:when> <xsl:otherwise> <xsl:text>\CSTUGtitle{</xsl:text> <xsl:choose> <xsl:when test="c:title[@lang=$lang]"> <xsl:value-of select="concat($lang, '}{')"/> <xsl:apply-templates select="c:title[@lang=$lang]"/> </xsl:when> <xsl:when test="c:title[@lang=../@lang]"> <xsl:value-of select="concat(@lang, '}{')"/> <xsl:apply-templates select="c:title[@lang=../@lang]"/> </xsl:when> <xsl:when test="c:title[@lang="cze"]"> <xsl:text>cze}{</xsl:text> <xsl:apply-templates select="c:title[@lang="cze"]"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="concat(c:title[1]/@lang, '}{')"/> <xsl:apply-templates select="c:title[1]"/> </xsl:otherwise> </xsl:choose> <xsl:text>} </xsl:text> <xsl:if test="$IncludeOriginalTitle!='' and $lang!=@lang and c:title[$lang=@lang] and c:title[@lang=../@lang]"> <xsl:value-of select="concat('\CSTUGtitle{', @lang, '}{')"/> <xsl:apply-templates select="c:title[@lang=../@lang]"/> <xsl:text>} </xsl:text> </xsl:if> </xsl:otherwise> </xsl:choose> </xsl:template>
<!-- If at least one keyword is present, they are output in the CSTUGkeywords environment. The XML documents store keywords as identifiers, in the TeX output they are expanded into a \CSTUGkeyword macro with two arguments, the language and the keyword. If the "lang" parameter was not used, each keyword is output in all available languages within the CSTUGkeywordset environment. The structure is a little different: the CSTUGkeywords contains one or more CSTUGkeywordset environments, one for each keaword, which in turn contains one or more \CSTUGkeyword macros, one for each language. Some keywords, typically acronyms and product names, have the same form in all languages. In such a case the table of keywords contains only one variant with the languages specified as ALL (all uppercase). -->
<xsl:template name="keywords"> <xsl:if test="count(c:keyword) > 0"> <xsl:text>\begin{CSTUGkeywords} </xsl:text> <xsl:for-each select="c:keyword"> <xsl:choose> <xsl:when test="$lang=''"> <xsl:text>\begin{CSTUGkeywordset} </xsl:text> <xsl:variable name="kwdid"> <xsl:value-of select="."/> </xsl:variable> <xsl:for-each select="$keywordlist"> <xsl:variable name="kwd" select="key('keyword', $kwdid)"/> <xsl:for-each select="$kwd/*"> <xsl:value-of select="concat('\keyword{', local-name(), '}{')"/> <xsl:apply-templates select="."/> <xsl:text>} </xsl:text> </xsl:for-each> </xsl:for-each> <xsl:text>\end{CSTUGkeywordset} </xsl:text> </xsl:when> <xsl:otherwise> <xsl:call-template name="c-keyword-TeX"> <xsl:with-param name="kwdid"> <xsl:value-of select="."/> </xsl:with-param> <xsl:with-param name="kwdlang"> <xsl:value-of select="$lang"/> </xsl:with-param> <xsl:with-param name="kwdlang2"> <xsl:value-of select="../@lang"/> </xsl:with-param> <xsl:with-param name="prefix">\keyword{</xsl:with-param> <xsl:with-param name="infix">}{</xsl:with-param> <xsl:with-param name="suffix">} </xsl:with-param> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:for-each> <xsl:text>\end{CSTUGkeywords} </xsl:text> </xsl:if> </xsl:template>
<!-- Font styles -->
<xsl:template match="c:b"> <xsl:text>\textbf{</xsl:text> <xsl:apply-templates/> <xsl:text>}</xsl:text> </xsl:template> <xsl:template match="c:i"> <xsl:text>\textit{</xsl:text> <xsl:apply-templates/> <xsl:text>}</xsl:text> </xsl:template> <xsl:template match="c:tt"> <xsl:text>\texttt{</xsl:text> <xsl:apply-templates/> <xsl:text>}</xsl:text> </xsl:template> <xsl:template match="c:em"> <xsl:text>\emph{</xsl:text> <xsl:apply-templates/> <xsl:text>}</xsl:text> </xsl:template>
<!-- TeX command, defined in csbulacronym.sty -->
<xsl:template match="c:cmd"> <xsl:text>\cmd{</xsl:text> <xsl:apply-templates/> <xsl:text>}</xsl:text> </xsl:template>
<!-- Paragraphs and lists -->
<xsl:template match="c:para"> <xsl:apply-templates/> <xsl:text/> </xsl:template> <xsl:template match="c:ul"> <xsl:text>\begin{itemize} </xsl:text> <xsl:apply-templates/> <xsl:text>\end{itemize} </xsl:text> </xsl:template> <xsl:template match="c:ol"> <xsl:text>\begin{enumerate} </xsl:text> <xsl:apply-templates/> <xsl:text>\end{enumerate} </xsl:text> </xsl:template> <xsl:template match="c:li"> <xsl:text>\item </xsl:text> <xsl:apply-templates/> <xsl:text/> </xsl:template>
<!-- Root of the included document -->
<xsl:template match="/" mode="xinclude"> <xsl:apply-templates/> </xsl:template> </xsl:stylesheet>

articles.xsl