--- /dev/null
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns="http://www.w3.org/1999/xhtml">
+
+<!-- Constants used for case translation -->
+<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'" />
+<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
+
+<!-- ==================================================================== -->
+<!-- Process a documentation section -->
+<!-- ==================================================================== -->
+<xsl:template match="section">
+<xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="section/title">
+<xsl:text>\subsection*{</xsl:text>
+<xsl:apply-templates/>
+<xsl:text>}</xsl:text><xsl:call-template name="label"/>
+<xsl:text>
+</xsl:text>
+</xsl:template>
+
+<xsl:template match="section/section/title">
+<xsl:text>\subsubsection*{</xsl:text>
+<xsl:apply-templates/>
+<xsl:text>}</xsl:text><xsl:call-template name="label"/>
+<xsl:text>
+</xsl:text>
+</xsl:template>
+
+<xsl:template match="section/section/section/title">
+<xsl:text>\subsubsection*{</xsl:text>
+<xsl:apply-templates/>
+<xsl:text>}</xsl:text><xsl:call-template name="label"/>
+<xsl:text>
+</xsl:text>
+</xsl:template>
+
+<xsl:template match="note/title"></xsl:template>
+<xsl:template match="example/title"></xsl:template>
+
+<xsl:template name="label">
+<xsl:if test="../@id">
+<xsl:variable name="metafile" select="document(/*/@metafile)/metafile" />
+<xsl:text>\label{</xsl:text><xsl:value-of
+select="$metafile/path"/><xsl:value-of
+select="$metafile/basename"/>
+<xsl:text>:</xsl:text>
+<xsl:value-of select="../@id"/>
+<xsl:text>}</xsl:text>
+</xsl:if>
+</xsl:template>
+
+
+<!-- ==================================================================== -->
+<!-- <example> -->
+<!-- ==================================================================== -->
+<!-- verbatim inside of fbox doesn't work for some reason -->
+<xsl:template match="example">
+<xsl:text>\par\smallskip\begin{center}</xsl:text>
+<xsl:if test="not(pre)"><xsl:text>\fbox{</xsl:text></xsl:if>
+<xsl:text>\begin{minipage}{.8\textwidth}\begin{flushleft}</xsl:text>
+<xsl:apply-templates select="title" mode="print" />
+<xsl:text>{\ttfamily\small </xsl:text>
+<xsl:text>\noindent </xsl:text><xsl:apply-templates/>
+<xsl:text>}</xsl:text>
+<xsl:text>\end{flushleft}\end{minipage}</xsl:text>
+<xsl:if test="not(pre)"><xsl:text>}</xsl:text></xsl:if>
+<xsl:text>\end{center}\par\smallskip</xsl:text>
+</xsl:template>
+
+<xsl:template match="example/title" mode="print">
+<xsl:text>\textbf{</xsl:text>
+ <xsl:apply-templates/>
+<xsl:text>}\\ </xsl:text>
+</xsl:template>
+
+
+<!-- ==================================================================== -->
+<!-- indentations -->
+<!-- ==================================================================== -->
+<xsl:template match="indent">
+<xsl:text>\begin{list}{}{\topsep 0pt\rightmargin 0pt\leftmargin 2em}
+\item[] </xsl:text>
+<xsl:apply-templates/>
+<xsl:text>\end{list}</xsl:text>
+</xsl:template>
+
+<!-- ==================================================================== -->
+<!-- <note> -->
+<!-- ==================================================================== -->
+<xsl:template match="note">
+<xsl:text>\par\smallskip
+{\Huge </xsl:text>
+<xsl:choose>
+<xsl:when test="@type='warning'">
+ <xsl:text>\fbox{!} </xsl:text>
+</xsl:when>
+<xsl:otherwise>
+ <xsl:text>$\Longrightarrow$</xsl:text>
+</xsl:otherwise>
+</xsl:choose>
+<xsl:text>}\begin{minipage}[t]{.8\textwidth}
+\noindent </xsl:text>
+<xsl:apply-templates select="title" mode="print" />
+<xsl:apply-templates/>
+<xsl:text>\end{minipage}\par\smallskip</xsl:text>
+</xsl:template>
+
+<xsl:template match="note/title" mode="print">
+<xsl:text>\textbf{</xsl:text>
+ <xsl:apply-templates/>
+<xsl:text>} \\
+\noindent </xsl:text>
+</xsl:template>
+
+
+<!-- ==================================================================== -->
+<!-- <directive> -->
+<!-- Inserts link to another directive, which might be in another module. -->
+<!-- References are converted into lower case. -->
+<!-- ==================================================================== -->
+<xsl:template match="directive" name="directive">
+<xsl:text>\textsc{</xsl:text>
+ <xsl:if test="@type='section'"><xsl:text>\textless{}</xsl:text></xsl:if>
+ <xsl:text>\hyperlink{/mod/</xsl:text>
+ <xsl:value-of select="@module"/>
+ <xsl:text>:</xsl:text>
+ <xsl:value-of select="translate(.,$uppercase,$lowercase)"/>
+ <xsl:text>}{</xsl:text>
+ <xsl:apply-templates/>
+ <xsl:text>}</xsl:text>
+ <xsl:if test="@type='section'"><xsl:text>\textgreater{}</xsl:text></xsl:if>
+<xsl:text>}</xsl:text>
+</xsl:template>
+<!-- /directive -->
+
+<!-- ==================================================================== -->
+<!-- <module> -->
+<!-- Inserts a link to refereed module -->
+<!-- ==================================================================== -->
+<xsl:template match="module" name="module">
+<xsl:text>\textsc{\hyperlink{/mod/</xsl:text>
+ <xsl:value-of select="."/>
+ <xsl:text>}{</xsl:text>
+ <xsl:apply-templates/>
+ <xsl:text>}</xsl:text>
+<xsl:text>}</xsl:text>
+</xsl:template>
+<!-- /module -->
+
+
+
+<!-- ==================================================================== -->
+<!-- <related> -->
+<!-- ==================================================================== -->
+<xsl:template match="related">
+<xsl:text>
+\fbox{\begin{tabular}{rr}
+\begin{minipage}[t]{.49\linewidth}
+\textbf{</xsl:text>
+<xsl:value-of select="$messages/message[@name='relatedmodules']" />
+<xsl:text>} \\
+</xsl:text>
+<xsl:for-each select="modulelist/module">
+<xsl:call-template name="module"/>
+<xsl:text> \\
+</xsl:text>
+</xsl:for-each>
+<xsl:text>
+\end{minipage} &
+\begin{minipage}[t]{.4\linewidth}
+\textbf{</xsl:text>
+<xsl:value-of select="$messages/message[@name='relateddirectives']" />
+<xsl:text>} \\
+</xsl:text>
+<xsl:for-each select="directivelist/directive">
+<xsl:call-template name="directive"/>
+<xsl:text> \\
+</xsl:text>
+</xsl:for-each>
+<xsl:text>
+\end{minipage}
+\end{tabular}}
+\smallskip
+</xsl:text>
+</xsl:template>
+
+
+<!-- ==================================================================== -->
+<!-- <seealso> -->
+<!-- ==================================================================== -->
+<xsl:template name="seealso">
+ <xsl:if test="seealso">
+ <xsl:text>\textbf{</xsl:text>
+ <xsl:value-of select="$messages/message [@name='seealso']" />
+ <xsl:text>}\begin{itemize}</xsl:text>
+ <xsl:for-each select="seealso">
+ <xsl:text>\item </xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>
+</xsl:text>
+ </xsl:for-each>
+<xsl:text>\end{itemize}</xsl:text>
+ </xsl:if>
+</xsl:template>
+
+
+<!-- ==================================================================== -->
+<!-- section-title -->
+<!-- ==================================================================== -->
+<xsl:template name="section-title">
+<xsl:variable name="metafile" select="document(/*/@metafile)/metafile" />
+<xsl:text>\section{</xsl:text><xsl:apply-templates select="title"/>
+<xsl:text>}</xsl:text>
+<xsl:text>\label{</xsl:text><xsl:value-of
+select="$metafile/path"/><xsl:value-of
+select="$metafile/basename"/>
+<xsl:text>}
+</xsl:text>
+</xsl:template>
+
+</xsl:stylesheet>
+
--- /dev/null
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns="http://www.w3.org/1999/xhtml">
+
+
+<!-- ==================================================================== -->
+<!-- Ordinary HTML that must be converted to latex -->
+<!-- ==================================================================== -->
+
+<xsl:template match="ul">
+<xsl:text>\begin{itemize}
+</xsl:text>
+<xsl:apply-templates/>
+<xsl:text>\end{itemize}
+</xsl:text>
+</xsl:template>
+
+<xsl:template match="ol">
+<xsl:text>\begin{enumerate}
+</xsl:text>
+<xsl:apply-templates/>
+<xsl:text>\end{enumerate}
+</xsl:text>
+</xsl:template>
+
+<xsl:template match="li">
+<xsl:text>\item </xsl:text>
+<xsl:apply-templates/>
+<xsl:text>
+</xsl:text>
+</xsl:template>
+
+<xsl:template match="dl">
+<xsl:text>\begin{description}
+</xsl:text>
+<xsl:apply-templates/>
+<xsl:text>\end{description}
+</xsl:text>
+</xsl:template>
+
+<xsl:template match="dt">
+<xsl:text>\item[</xsl:text><xsl:apply-templates/>
+<xsl:text>] </xsl:text>
+</xsl:template>
+
+<xsl:template match="dd">
+<xsl:apply-templates/>
+</xsl:template>
+
+<!-- Latex doesn't like successive line breaks, so replace any
+ sequence of two or more br separated only by white-space with
+ one line break followed by smallskips. -->
+<xsl:template match="br">
+<xsl:choose>
+<xsl:when test="name(preceding-sibling::node()[1])='br' or name(preceding-sibling::node()[1])='indent'">
+<xsl:text>\smallskip </xsl:text>
+</xsl:when>
+<xsl:when test="name(preceding-sibling::node()[2])='br' or name(preceding-sibling::node()[2])='indent'">
+ <xsl:choose>
+ <xsl:when test="normalize-space(preceding-sibling::node()[1])=''">
+ <xsl:text>\smallskip </xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- Don't put a line break if we are the last thing -->
+ <xsl:if test="not(position()=last()) and not(position()=last()-1 and normalize-space(following-sibling::node()[1])='')">
+ <xsl:text>\\ </xsl:text>
+ </xsl:if>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:when>
+<xsl:otherwise>
+ <!-- Don't put a line break if we are the last thing -->
+ <xsl:if test="not(position()=last()) and not(position()=last()-1 and normalize-space(following-sibling::node()[1])='')">
+ <xsl:text>\\ </xsl:text>
+ </xsl:if>
+</xsl:otherwise>
+</xsl:choose>
+</xsl:template>
+
+<xsl:template match="p">
+<xsl:apply-templates/>
+<xsl:text>\par
+</xsl:text>
+</xsl:template>
+
+<xsl:template match="code">
+<xsl:text>\texttt{</xsl:text>
+<xsl:apply-templates/>
+<xsl:text>}</xsl:text>
+</xsl:template>
+
+<xsl:template match="strong">
+<xsl:text>\textbf{</xsl:text>
+<xsl:apply-templates/>
+<xsl:text>}</xsl:text>
+</xsl:template>
+
+<xsl:template match="em">
+<xsl:text>\textit{</xsl:text>
+<xsl:apply-templates/>
+<xsl:text>}</xsl:text>
+</xsl:template>
+
+<!-- Value-of used here explicitly because we don't wan't latex-escaping
+performed. Of course, this will conflict with html where some tags are
+interpreted in pre -->
+<xsl:template match="pre">
+<xsl:text>\begin{verbatim}
+</xsl:text>
+<xsl:value-of select="."/>
+<xsl:text>\end{verbatim}
+</xsl:text>
+</xsl:template>
+
+<xsl:template match="blockquote">
+<xsl:text>\begin{quotation}
+</xsl:text>
+<xsl:apply-templates/>
+<xsl:text>\end{quotation}
+</xsl:text>
+</xsl:template>
+
+<!-- XXX: We need to deal with table headers -->
+
+<xsl:template match="table">
+<xsl:variable name="table-type">
+ <xsl:choose>
+ <xsl:when test="count(tr) > 15">longtable</xsl:when>
+ <xsl:otherwise>tabular</xsl:otherwise>
+ </xsl:choose>
+</xsl:variable>
+
+<xsl:text>\begin{</xsl:text><xsl:value-of select="$table-type"/>
+<xsl:text>}{|</xsl:text>
+<xsl:choose>
+<xsl:when test="columnspec">
+ <xsl:for-each select="columnspec/column">
+ <xsl:text>l</xsl:text>
+ <xsl:if test="../../@border and not(position()=last())">
+ <xsl:text>|</xsl:text>
+ </xsl:if>
+ </xsl:for-each>
+</xsl:when>
+<xsl:otherwise>
+ <xsl:for-each select="tr[1]/*">
+ <xsl:text>l</xsl:text>
+ <xsl:if test="../../@border and not(position()=last())">
+ <xsl:text>|</xsl:text>
+ </xsl:if>
+ </xsl:for-each>
+</xsl:otherwise>
+</xsl:choose>
+<xsl:text>|}\hline
+</xsl:text>
+<xsl:apply-templates select="tr"/>
+<xsl:text>\hline\end{</xsl:text>
+<xsl:value-of select="$table-type"/>
+<xsl:text>}
+</xsl:text>
+</xsl:template>
+
+<xsl:template match="tr">
+ <xsl:apply-templates select="td|th"/>
+ <xsl:text>\\</xsl:text>
+ <xsl:if test="../@border and not(position()=last())">
+ <xsl:text>\hline</xsl:text>
+ </xsl:if>
+ <xsl:text>
+</xsl:text>
+</xsl:template>
+
+<xsl:template match="td">
+ <xsl:variable name="pos" select="position()"/>
+ <xsl:text>\begin{minipage}[t]{</xsl:text>
+ <xsl:choose>
+ <xsl:when test="../../columnspec">
+ <xsl:value-of select="../../columnspec/column[$pos]/@width"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select=".95 div last()"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:text>\textwidth}\small </xsl:text>
+ <xsl:apply-templates/>
+ <xsl:text>\end{minipage}</xsl:text>
+ <xsl:if test="not(position()=last())">
+ <xsl:text> & </xsl:text>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="th">
+ <xsl:variable name="pos" select="position()"/>
+ <xsl:text>\begin{minipage}[t]{</xsl:text>
+ <xsl:choose>
+ <xsl:when test="../../columnspec">
+ <xsl:value-of select="../../columnspec/column[$pos]/@width"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select=".95 div last()"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:text>\textwidth}\bfseries </xsl:text>
+ <xsl:apply-templates/>
+ <xsl:text>\end{minipage}</xsl:text>
+ <xsl:if test="not(position()=last())">
+ <xsl:text> & </xsl:text>
+ </xsl:if>
+</xsl:template>
+
+<!--
+ This is a horrible hack, but it seems to mostly work. It does a
+ few things:
+
+ 1. Transforms references starting in http:// to footnotes with the
+ appropriate hyperref macro to make them clickable. (This needs
+ to be expanded to deal with news: and needs to be adjusted to
+ deal with "#", which is creating bad links at the moment.)
+
+ 2. For intra-document references, constructs the appropriate absolute
+ reference using a latex \pageref.
+ This involves applying a simplified version of the
+ general URL resolution rules to deal with ../. It only works for
+ one level of subdirectory.
+
+ 3. It is also necessary to deal with the fact that index pages
+ get references as "/".
+-->
+<xsl:template match="a">
+<xsl:apply-templates/>
+<xsl:if test="@href">
+<xsl:variable name="relpath" select="document(/*/@metafile)/metafile/relpath" />
+<xsl:variable name="path" select="document(/*/@metafile)/metafile/path" />
+<xsl:variable name="fileref">
+ <xsl:choose>
+ <xsl:when test="contains(@href, '.html')">
+ <xsl:value-of select="substring-before(@href, '.html')"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="concat(@href, 'index')"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:variable>
+<xsl:choose>
+
+<xsl:when test="starts-with(@href, 'http:') or starts-with(@href, 'news:') or starts-with(@href, 'mailto:')">
+ <xsl:if test="not(.=@href)">
+ <xsl:text>\footnote{</xsl:text>
+ <xsl:text>\href{</xsl:text>
+ <xsl:call-template name="replace-string">
+ <xsl:with-param name="text" select="@href"/>
+ <xsl:with-param name="replace" select="'#'"/>
+ <xsl:with-param name="with" select="'\#'"/>
+ </xsl:call-template>
+ <xsl:text>}{</xsl:text>
+ <xsl:call-template name="ltescape">
+ <xsl:with-param name="string" select="@href"/>
+ </xsl:call-template>
+ <xsl:text>}}</xsl:text>
+ </xsl:if>
+</xsl:when>
+<xsl:when test="starts-with(@href, '#')">
+<!-- Don't do inter-section references -->
+</xsl:when>
+<xsl:otherwise>
+ <xsl:text> (p.\ \pageref{</xsl:text>
+ <xsl:call-template name="replace-string">
+ <xsl:with-param name="replace" select="'#'"/>
+ <xsl:with-param name="with" select="':'"/>
+ <xsl:with-param name="text">
+ <xsl:choose>
+ <xsl:when test="$relpath='.'">
+ <xsl:value-of select="concat('/',$fileref)"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:choose>
+ <xsl:when test="starts-with($fileref,'..')">
+ <xsl:value-of select="substring-after($fileref,'..')"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="concat($path,$fileref)"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:with-param>
+ </xsl:call-template>
+ <xsl:text>}) </xsl:text>
+</xsl:otherwise>
+</xsl:choose>
+</xsl:if>
+</xsl:template>
+
+<xsl:template match="img">
+<xsl:text>[Image not coverted]</xsl:text>
+<!--
+<xsl:variable name="path" select="document(/*/@metafile)/metafile/path" />
+<xsl:text>\includegraphics{</xsl:text>
+<xsl:value-of select="concat('.',$path,@src)"/>
+<xsl:text>}</xsl:text>
+-->
+</xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:output
+ method="text"
+ encoding="ISO-8859-1"
+ indent="no"
+/>
+
+<!-- Read the localized messages from the specified language file -->
+<xsl:variable name="messages" select="document('../lang/en.xml')/messages"/>
+
+<!-- Get the guts of the stylesheets -->
+<xsl:include href="manualpage.xsl" />
+<xsl:include href="common.xsl" />
+<xsl:include href="html.xsl" />
+<xsl:include href="synopsis.xsl" />
+<xsl:include href="moduleindex.xsl" />
+<xsl:include href="directiveindex.xsl" />
+<xsl:include href="faq.xsl" />
+<xsl:include href="quickreference.xsl" />
+
+<xsl:template match="sitemap">
+<xsl:text>
+\documentclass[10pt]{book}
+\usepackage{times}
+\usepackage{longtable}
+\usepackage{style/latex/atbeginend}
+%\usepackage[pdftex]{color}
+\usepackage[colorlinks=true,letterpaper=true,linkcolor=blue,urlcolor=blue]{hyperref}
+
+% Let LaTeX be lenient about very-bad line wrapping.
+\tolerance=9999
+\emergencystretch=60pt
+
+% Adjust margins to a reasonable level
+\topmargin 0pt
+\advance \topmargin by -\headheight
+\advance \topmargin by -\headsep
+\textheight 8.9in
+\oddsidemargin 0pt
+\evensidemargin \oddsidemargin
+\marginparwidth 0.5in
+\textwidth 6.5in
+
+% Keep paragraphs flush left (rather than the default of indenting
+% the first line) and put a space between paragraphs.
+\setlength{\parindent}{0ex}
+\addtolength{\parskip}{1.2ex}
+
+% Shrink the inter-item spaces
+\AfterBegin{itemize}{\setlength{\itemsep}{0em}}
+
+\pagestyle{headings}
+
+\hypersetup{
+ pdftitle={</xsl:text>
+<xsl:value-of select="$messages/message[@name='apache']" />
+<xsl:text> </xsl:text>
+<xsl:value-of select="$messages/message[@name='http-server']" />
+<xsl:text> </xsl:text>
+<xsl:value-of select="$messages/message[@name='documentation']" />
+<xsl:text> </xsl:text>
+<xsl:value-of select="$messages/message[@name='version']" />
+<xsl:text>},
+ pdfauthor={Apache Software Foundation}
+ }
+
+\title{</xsl:text>
+<xsl:value-of select="$messages/message[@name='apache']" />
+<xsl:text> </xsl:text>
+<xsl:value-of select="$messages/message[@name='http-server']" />
+<xsl:text> </xsl:text>
+<xsl:value-of select="$messages/message[@name='documentation']" />
+<xsl:text> </xsl:text>
+<xsl:value-of select="$messages/message[@name='version']" />
+<xsl:text>}
+\author{Apache Software Foundation}
+\date{\today}
+
+\begin{document}
+\frontmatter
+\maketitle
+
+\section*{About The PDF Documentation}
+
+This is an early release of the PDF version of the Apache
+Documentation. It is converted from XML source files, and may contain
+some errors and inconsistencies. If you have difficulty reading a
+part of this file, please consult instead the HTML version of the
+documentation on the Apache HTTP Server website.
+
+\tableofcontents
+\mainmatter
+</xsl:text>
+
+<xsl:for-each select="category">
+ <xsl:text>\chapter{</xsl:text>
+ <xsl:apply-templates select="title" mode="printcat"/>
+ <xsl:text>}
+</xsl:text>
+ <xsl:apply-templates/>
+</xsl:for-each>
+
+<xsl:text>\end{document}</xsl:text>
+</xsl:template>
+
+<xsl:template match="page">
+<xsl:text>\include{</xsl:text>
+<xsl:choose>
+<xsl:when test="contains(@href,'.')">
+ <xsl:value-of select="substring-before(@href,'.')"/>
+</xsl:when>
+<xsl:otherwise>
+ <xsl:value-of select="concat(@href,'index')"/>
+</xsl:otherwise>
+</xsl:choose>
+<xsl:text>}
+</xsl:text>
+</xsl:template>
+
+<xsl:template match="category/title" mode="printcat">
+<xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="category/title"></xsl:template>
+
+<xsl:template match="modulefilelist">
+<xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="modulefile">
+<xsl:text>\include{mod/</xsl:text>
+<xsl:value-of select="substring-before(.,'.')"/>
+<xsl:text>}
+</xsl:text>
+</xsl:template>
+
+<xsl:template match="summary">
+<xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template name="replace-string">
+ <xsl:param name="text"/>
+ <xsl:param name="replace"/>
+ <xsl:param name="with"/>
+
+ <xsl:choose>
+ <xsl:when test="not(contains($text,$replace))">
+ <xsl:value-of select="$text"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="substring-before($text,$replace)"/>
+ <xsl:value-of select="$with"/>
+ <xsl:call-template name="replace-string">
+ <xsl:with-param name="text" select="substring-after($text,$replace)"/>
+ <xsl:with-param name="replace" select="$replace"/>
+ <xsl:with-param name="with" select="$with"/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!-- ==================================================================== -->
+<!-- Take care of all the LaTeX special characters. -->
+<!-- Silly multi-variable technique used to avoid deep recursion. -->
+<!-- ==================================================================== -->
+<xsl:template match="text()">
+<xsl:call-template name="ltescape">
+ <xsl:with-param name="string" select="."/>
+</xsl:call-template>
+</xsl:template>
+
+
+<xsl:template name="ltescape">
+<xsl:param name="string"/>
+
+<xsl:variable name="result1">
+ <xsl:choose>
+ <xsl:when test="contains($string, '\')">
+ <xsl:call-template name="replace-string">
+ <xsl:with-param name="replace" select="'\'"/>
+ <xsl:with-param name="with" select="'\textbackslash '"/>
+ <xsl:with-param name="text" select="normalize-space($string)"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$string"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:variable>
+
+<xsl:variable name="result2">
+ <xsl:choose>
+ <xsl:when test="contains($result1, '$')">
+ <xsl:call-template name="replace-string">
+ <xsl:with-param name="replace" select="'$'"/>
+ <xsl:with-param name="with" select="'\$'"/>
+ <xsl:with-param name="text" select="$result1"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$result1"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:variable>
+
+<xsl:variable name="result3">
+ <xsl:choose>
+ <xsl:when test="contains($result2, '{')">
+ <xsl:call-template name="replace-string">
+ <xsl:with-param name="replace" select="'{'"/>
+ <xsl:with-param name="with" select="'\{'"/>
+ <xsl:with-param name="text" select="$result2"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$result2"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:variable>
+
+<xsl:variable name="result4">
+ <xsl:choose>
+ <xsl:when test="contains($result3, '}')">
+ <xsl:call-template name="replace-string">
+ <xsl:with-param name="replace" select="'}'"/>
+ <xsl:with-param name="with" select="'\}'"/>
+ <xsl:with-param name="text" select="$result3"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$result3"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:variable>
+
+<!-- The '[' and ']' characters don't, in general, need to be
+ escaped. But there are times when it is ambiguous whether
+ [ is the beginning of an optional argument or a literal '['.
+ Hence, it is safer to protect the literal ones with {}. -->
+<xsl:variable name="result5">
+ <xsl:choose>
+ <xsl:when test="contains($result4, '[')">
+ <xsl:call-template name="replace-string">
+ <xsl:with-param name="replace" select="'['"/>
+ <xsl:with-param name="with" select="'{[}'"/>
+ <xsl:with-param name="text" select="$result4"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$result4"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:variable>
+
+<xsl:variable name="result6">
+ <xsl:choose>
+ <xsl:when test="contains($result5, ']')">
+ <xsl:call-template name="replace-string">
+ <xsl:with-param name="replace" select="']'"/>
+ <xsl:with-param name="with" select="'{]}'"/>
+ <xsl:with-param name="text" select="$result5"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$result5"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:variable>
+
+<xsl:variable name="result7">
+ <xsl:choose>
+ <xsl:when test="contains($result6, '"')">
+ <xsl:call-template name="replace-string">
+ <xsl:with-param name="replace" select="'"'"/>
+ <xsl:with-param name="with" select="'\texttt{"}'"/>
+ <xsl:with-param name="text" select="$result6"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$result6"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:variable>
+
+
+ <xsl:call-template name="replace-string">
+ <xsl:with-param name="replace" select="'_'"/>
+ <xsl:with-param name="with" select="'\_'"/>
+ <xsl:with-param name="text">
+ <xsl:call-template name="replace-string">
+ <xsl:with-param name="replace" select="'#'"/>
+ <xsl:with-param name="with" select="'\#'"/>
+ <xsl:with-param name="text">
+ <xsl:call-template name="replace-string">
+ <xsl:with-param name="replace" select="'%'"/>
+ <xsl:with-param name="with" select="'\%'"/>
+ <xsl:with-param name="text">
+ <xsl:call-template name="replace-string">
+ <xsl:with-param name="replace" select="'>'"/>
+ <xsl:with-param name="with" select="'\textgreater{}'"/>
+ <xsl:with-param name="text">
+ <xsl:call-template name="replace-string">
+ <xsl:with-param name="replace" select="'<'"/>
+ <xsl:with-param name="with" select="'\textless{}'"/>
+ <xsl:with-param name="text">
+ <xsl:call-template name="replace-string">
+ <xsl:with-param name="replace" select="'~'"/>
+ <xsl:with-param name="with" select="'\textasciitilde{}'"/>
+ <xsl:with-param name="text">
+ <xsl:call-template name="replace-string">
+ <xsl:with-param name="replace" select="'^'"/>
+ <xsl:with-param name="with" select="'\^{}'"/>
+ <xsl:with-param name="text">
+ <xsl:call-template name="replace-string">
+ <xsl:with-param name="replace" select="'&'"/>
+ <xsl:with-param name="with" select="'\&'"/>
+ <xsl:with-param name="text" select="$result7"/>
+ </xsl:call-template>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:with-param>
+ </xsl:call-template>
+
+</xsl:template>
+
+</xsl:stylesheet>