Re: output method (discussion)

Subject: Re: output method (discussion)
From: Denys Duchier <Denys.Duchier@xxxxxxxxxxxx>
Date: 19 Aug 1999 14:16:08 +0200
vidarg@xxxxxx (Vidar B. Gundersen) writes:

> What if I use XSLT to write LaTeX code? In that case, I need to handle
> the reserved charactes by escaping them:
>     $ & % # _ { } ~ ^ \
> So if the converter (might be the XSLT engine) encounter an &amp;
> (XML) it should not write & (text), but something like {\&}.
> 
> What is a good way of handling this?

I have to deal with precisely this issue of converting XML documents
into LaTeX.  XT supports an additional output method xt:nxml, but I
have found it to be insufficiently flexible for defining escaping
policies for LaTeX output.  Fortunately, XT makes it possible to
define your own output handler and that's what I have done - I call it
MapOutputHandler.  Code and documentation can be obtained from:

                http://www.ps.uni-sb.de/~duchier/xsl/

The idea, in a nutshell, is to allow you to define named escape maps
and to select them by name.

        <define name="latex.text">
          <escape char="$">\escDollar </escape>
          <escape char="&amp;">\escAmp </escape>
          ...
          <escape char="&#10;"> \escNone
</escape>
        </define>

Note that it is important to escape newlines since two in a row
otherwise mean \par; however, you should not remove them from the
input because otherwise you get very long lines that exceed TeX's
input buffer.  You might define similar maps for code elements.
For index elements that translate into \index{...} commands, you need
to be somewhat more careful since \index commands give special meaning
to certain characters that need to be quoted using a different
mechanism, i.e. by prefixing with character `"'.

        <define name="index.text">
          <include name="latex.text"/>
          <escape char='"'>""</escape>
          ...
        </define>

Since you typically want to process the content of index elements
using the same templates as for the rest of your document, but using
more restrictive escaping policies, you can temporarily alias one
policy to another:

        <alias name="latex.text" to="index.text">
          <alias name="latex.code" to="index.code">
            ...
          </alias>
        </alias>

Hope this helps.
Cheers,

-- 
Dr. Denys Duchier			Denys.Duchier@xxxxxxxxxxxx
Forschungsbereich Programmiersysteme	(Programming Systems Lab)
Universitaet des Saarlandes, Geb. 45	http://www.ps.uni-sb.de/~duchier
Postfach 15 11 50			Phone: +49 681 302 5618
66041 Saarbruecken, Germany		Fax:   +49 681 302 5615


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread