<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="ExtremeXSLT/extreme-html.xsl"?>
<paper secnumbers="1">
<front>
<title>xmLP — a Literate Programming Tool for XML &amp; Text</title>
<conference>Extreme Markup Languages 2002</conference>
<author contact="0">
  <fname>Anthony B.</fname><surname>Coates</surname>
  <address><affil>Financial XML Specialist</affil><city>London</city><cntry>United Kingdom</cntry><email>abcoates@TheOffice.net</email><phone>+44 (20) 7237 1096</phone></address>
  <bio><para>Anthony B. Coates was most recently Leader of XML Architecture &amp; Design in
Reuters Chief Technology Office, and represented Reuters on technical working
groups for <acronym.grp><acronym>FpML</acronym><expansion>Financial Products Markup Language</expansion></acronym.grp> and <acronym.grp><acronym>MDDL</acronym><expansion>Market Data Definition Language</expansion></acronym.grp>.
Tony recommended XML technologies and design strategies to product
groups within Reuters to co-ordinate the business usage of XML and leverage the
best available solutions. This included both general XML technologies and
specific vertical market XML languages. His background includes developing
software for technical analysis &amp; financial graphics, developing multimedia
&amp; Web applications, and theoretical &amp; experimental physics. He has
worked with XML since 1998, and Literate Programming since 1996.
Tony is a past secretary of the Australian Java Users Group.</para></bio>
</author>
<author contact="1">
  <fname>Zarella</fname><surname>Rendon</surname>
  <address><affil>XML Factor &amp; W3C XSL WG</affil><aline>2312 Treyburn Ct.</aline><city>Plano</city><state>Texas</state><postcode>75075</postcode><cntry>USA</cntry><email>zarella@xml-factor.com</email><phone>+1 (214) 762 5655</phone><fax>+1 (972) 424 5482</fax><web>http://www.xml-factor.com</web></address>
  <bio><para>Zarella Rendon is an XML/SGML expert with over 10 years of experience in the industry. Ms. Rendon began working with SGML transformations in 1992 as an engineer at Northern Telecom, and continued working with SGML, XML and related standards at ISOGEN International, where she was an applications engineer as well as a co-founder. Currently working as an independent consultant, Ms. Rendon offers a unique perspective and legacy of experience to the XML/SGML community at large. Ms. Rendon is a member of several XML industry groups, including OASIS and the W3C XSL Working Group, where she strives to help further the development, support, and use of public standards.</para></bio></author>
<keywords>
<keyword>literate programming</keyword>
<keyword>LitProg</keyword>
<keyword>Donald Knuth</keyword>
<keyword>xmLP</keyword></keywords>
<abstract><para><acronym.grp><acronym>LitProg</acronym><expansion>Literate Programming</expansion></acronym.grp> is a technique created by Donald Knuth
to make computer programs readable and maintainable.  This article introduces <acronym>LitProg</acronym>, demonstrates what a literate program looks like,
and describes the  <acronym>LitProg</acronym> tool “xmLP”, which can be used to literately develop program sources (or other control file sources)
whose content is XML or text.</para></abstract></front>
<body>
  <section><title>Overview of Literate Programming</title>
    <para>The legendary computer luminary Donald Knuth <bibref refloc="bib-knuth-www"/> once asked why nobody ever takes a computer program to bed to read.
The answer was simple — most computer programs are unreadable.
Comments are too few and too far between, and the simple process of reading
becomes the painful process of reverse engineering.  Knuth's solution was
that programs should <highlight style="bold">not</highlight> be 90% code and 10% comments, they should be 90% descriptive
text and 10% code.  This was the start of Literate Programming, or “<acronym>LitProg</acronym>” <bibref refloc="bib-lp-www"/>.</para>
    
  <subsec1><title>Documentation of Programs</title><para>In the early days of computer programming, documentation within the source code of a program was an unaffordable luxury.  Some systems actively stripped comments from code in order to save storage.  Although storage no longer tends to be a significant limit, programmers still spend little time on documenting their code.  There are several reasons for this.  One is that programmers tend to be judged by whether their code works (or appears to), not by how well it is commented.  Further, if project managers need to cut something from a development schedule, documentation is an item that can be removed from the schedule without forcibly affecting the delivered functionality.</para><para>On a personal level, during the fleeting moments that a programmer writes a particular piece of code, that code can appear to be so clear and obvious that documentation seems all but unnecessary.  It is only when the programmer returns to the code after a month or more, all moments of clarity lost in the past, that the impact becomes obvious.  The situation is even worse when a different programmer has to work on the code.  With no documentation to read, the code needs to be reverse engineered in order to understand its intent and logic, but this is difficult to do with sufficient accuracy.  Too often, the code is rewritten in the belief that rewriting  is easier than reverse engineering.  This squanders any experience gained by the original programmer, while simultaneously introducing new bugs into the code base.</para><para>No documentation system can force an undisciplined or lazy programmer to document their code, but there are things that can be done to make the task less onerous.  <acronym>LitProg</acronym> tools, which allow code fragments to be interspersed within the documentation, put the documentation for a piece of code right beside that code, in the same file.  Compared to having code and documentation in separate files, this greatly increases the chance that as code is modified, the documentation is also modified to keep it up to date.</para></subsec1>
    <subsec1><title>LitProg</title><para>A “literate program” (or “literate document”) is a human readable document
containing short sections of code (known variously as “macros”, “chunks”, or “fragments”),
written and ordered so that it can be understood easily by people.  By contrast,
most computer programs are ordered purely for the benefit of program compilers.
In a literate program, source code fragments (or any textual fragments)
can appear in any suitable order.  When the literate document is processed, the code fragments are assembled into the order required
to produce the source files by “tangling” the document, to introduce Knuth's terminology.
Literate documents are also “woven” to convert them into a final documentation format.
Traditionally the documentation format was TeX or LaTeX, but these days it can also be
<acronym.grp><acronym>(X)HTML</acronym><expansion>(Extensible) Hypertext Markup Language</expansion></acronym.grp>,
<acronym.grp><acronym>XSLFO</acronym><expansion>Extensible Stylesheet Language Formatting Objects</expansion></acronym.grp>,
or <acronym.grp><acronym>PDF</acronym><expansion>Portable Document Format, aka Acrobat</expansion></acronym.grp>.</para></subsec1>
  <subsec1>
    <title>LitProg Tools</title>
    <para>What follows is a non-exhaustive list of <acronym>LitProg</acronym> tools.  All of these tools predate XML.
References to further information can be found in the bibliography.</para>
    <deflist>
     <def.item>
       <def.term>WEB</def.term>
      <def>
        <para>WEB was Knuth's original <acronym>LitProg</acronym> system for Pascal.
WEB directly marks up many of the syntactic features of Pascal, so that in creating a valid
WEB document, a programmer has pre-validated much of the syntax of the code fragments.
Note that WEB was written before the <acronym.grp><acronym>WWW</acronym><expansion>World Wide Web</expansion></acronym.grp>
came to prominence.  Knuth's choice of name relates to his ideas of tangling and weaving.
<bibref refloc="bib-knuth-92"/></para></def></def.item>
      <def.item>
      <def.term>CWEB</def.term>
      <def>
       <para>Also produced by Knuth's group, CWEB supported C rather than Pascal.
It has now been extended to handle C++ and Java as well.
<bibref refloc="bib-cweb-www"/></para></def></def.item>
      <def.item>
      <def.term>FWEB</def.term>
      <def>
        <para>FWEB is a multi-language <acronym>LitProg</acronym> tool which is
similar in spirit to WEB &amp; CWEB.  It was the first <acronym>LitProg</acronym> tool
to support Fortran.
<bibref refloc="bib-fweb-www"/></para></def></def.item>
      <def.item>
      <def.term>noweb</def.term>
      <def>
       <para>noweb is the most well-known of the language-insensitive
<acronym>LitProg</acronym> tools.  These tools do not provide any syntactic
support for any computer languages, and treat all code fragments as nothing
more than text fragments.  Language-insensitive <acronym>LitProg</acronym>
tools can be used for any (textual) programming language or control files,
so their loss of syntactic support is compensated for by a gain in flexibility.
<bibref refloc="bib-noweb-www"/></para></def></def.item>
      <def.item>
      <def.term>FunnelWeb</def.term>
      <def>
        <para>FunnelWeb is another language-insensitive tool.  Its unique feature
is that its macros can have parameters, providing some of the power of a language
pre-processor.  xmLP, the XML <acronym>LitProg</acronym> tool described in this paper,
takes its inspiration most strongly from FunnelWeb.
<bibref refloc="bib-funnelweb-www"/></para></def></def.item>
      <def.item>
      <def.term>SWEB</def.term>
      <def>
        <para>SWEB is C. Michael Sperberg-McQueen's SGML <acronym>LitProg</acronym> tool.
It was the first <acronym>LitProg</acronym> tool whose document format could feasibly be
parsed by something other than the tool itself.
<bibref refloc="bib-sweb-www"/></para></def></def.item></deflist></subsec1>
  <subsec1>
    <title>Javadoc</title>
   <para>Sun's Javadoc is a powerful tool for generating reference documentation from comments
embedded in Java code, and has inspired similar tools for other programming languages.
Javadoc is ideal for documenting the available methods &amp; classes in a Java
<acronym.grp><acronym>API</acronym><expansion>Application Programming Interface</expansion></acronym.grp>.
However, Javadoc is not a LitProg tool.</para>
    <para>The documentation that Javadoc produces extends down only the the method signatures.
It does not provide any support for documenting the workings of individual methods.  It does
not allow the order in which methods/classes are presented to be controlled to improve readability.
These are not criticisms, just observations.  There is no such thing as one size fits all documentation.
Indeed, there are at least 3 major classes of documentation:</para>
    <seqlist number="arabic">
     <li><para>User (functional) documentation;</para></li>
    <li><para>Detailed documentation within methods (functions) of the what, why, and how of the code;</para></li>
    <li><para>Reference documentation which lists the available methods (functions) in an <acronym>API</acronym> (library).</para></li>
   </seqlist>
   <para><acronym>LitProg</acronym> tools do a good job of generating detailed documentation.
Javadoc does a good job of generating reference documentation.  Neither provides sufficient support
for generating good user documentation.  So, not all documentation is the same, and no documentation
tool is suitable for every type of documentation.  This paper focuses on <acronym>LitProg</acronym> tools,
and hence on the problem of creating detailed documentation of the workings of program code.</para></subsec1></section>
  <section>
    <title>A LitProg Scenario</title>
    <para>This paper was written as a literate program, using an extended version of the “Extreme Markup Languages 2002” DTD.
   The literate document was processed twice using an XML LitProg tool, “xmLP” <bibref refloc="bib-xmLP-www"/>, which is described in this paper.  The literate document was first “tangled”, where the macros were expanded to produce the source files.  It was then “woven”, where the macros were cross-referenced and this document was generated.  Both processes need to resolve the macros in the document, but for different purposes.</para><para><highlight style="bold">No source code fragments</highlight> were copied into the literate document, because the literate document is the original source material from which the source code files are produced.</para><para>  The following scenario illustrates how
   literate programs can be a valuable tool for maintaining synchronized files.  <highlight style="bold">Note:</highlight> if at any stage you want to jump ahead to read about the <acronym>LitProg</acronym> tool “xmLP”, you can go directly  to Section <xref refloc="section-using-xmLP" type="number"/>.  However, you are encouraged to read this section first to get a sense of what a <acronym>LitProg</acronym> tool needs to achieve.</para>   
    <subsec1>
     <title></title>
      <para><highlight style="ital">This demonstrates the documentation created by xmLP.  So this section shows the output format.  The input format is discussed in Section <xref refloc="section-using-xmLP" type="number"/>.</highlight></para><para>Consider the problem of representing the way a particular stock market share price changes over time (a “time series”).  Taking a simplified view,
      a single daily price summary, which is an “event” from the time series, can be written as</para>
      <figure id="xmLPmacro1orcamPLmx" anchor="float"><verbatim format="linespecific"><highlight style="bold">xmLP Macro</highlight> “Time Series Event Instance” [<highlight style="bold">#1</highlight>] =</verbatim><verbatim format="linespecific">&lt;event date="<highlight style="bold">2002-02-20</highlight>"&gt;<highlight style="bold"/>
  &lt;open&gt;<highlight style="bold">85.70</highlight>&lt;/open&gt;<highlight style="bold"/>
  &lt;high&gt;<highlight style="bold">92.10</highlight>&lt;/high&gt;<highlight style="bold"/>
  &lt;low&gt;<highlight style="bold">81.37</highlight>&lt;/low&gt;<highlight style="bold"/>
  &lt;close&gt;<highlight style="bold">86.05</highlight>&lt;/close&gt;<highlight style="bold"/>
  &lt;volume multiplier="<highlight style="bold">1000</highlight>"&gt;<highlight style="bold">811786</highlight>&lt;/volume&gt;<highlight style="bold"/>
&lt;/event&gt;</verbatim><para><highlight style="ital">This macro is invoked in file</highlight> #2 (Figure <xref refloc="xmLPfile2elifPLmx" type="number"/>)</para><para><highlight style="ital">This macro is invoked in file</highlight> #4 (Figure <xref refloc="xmLPfile4elifPLmx" type="number"/>)</para></figure>
      <para><highlight style="ital">Note: this shows how xmLP XML macro definitions are “woven” into the documentation.  Note the automatically generated cross-references.</highlight></para><para>Here, “date” is the date of the event, “open” is the
opening (starting) price for that day, “high” and “low” are the
maximum and minimum prices for that day (respectively), and “close”
is the closing (final) price for that day.  The “volume” is the
number of shares traded during that day, and is commonly given in
terms of thousands of shares traded.</para>
      <para>The purpose of this example is to produce <highlight style="bold">both</highlight> a DTD and a W3C XML Schema to describe this event structure, within the limits of what each of these schema technologies can do.
A knowledge of DTD and W3C XML Schema constructs is assumed.</para>
   </subsec1>
   <subsec1>
     <title>open, high, low, close</title>
      <para>The “open”, “high”, “low”, and “close” elements each
contain a decimal number.  In the DTD, decimal numbers can only
be represented as unconstrained text.  However, a suitably named
entity can be used to suggest to human readers that decimal values
should be used.</para>
      <figure id="xmLPmacro2orcamPLmx" anchor="float"><verbatim format="linespecific"><highlight style="bold">xmLP Macro</highlight> “DTD: decimal pseudo-definition” [<highlight style="bold">#2</highlight>] =</verbatim><verbatim format="linespecific">&lt;!ENTITY % Decimal "#PCDATA"&gt;</verbatim><para><highlight style="ital">This macro is invoked in macro</highlight> #3 (Figure <xref refloc="xmLPmacro3orcamPLmx" type="number"/>)</para></figure>  
      <para><highlight style="ital">Note: this shows how xmLP text macro definitions are “woven” into the documentation.</highlight></para><para>From a machine perspective, this is nothing more than a
syntactic nicety.  However, it makes maintenance easier for humans
(by making the intent clear), and that makes it worth doing.</para>
      <figure id="xmLPmacro3orcamPLmx" anchor="float"><verbatim format="linespecific"><highlight style="bold">xmLP Macro</highlight> “DTD: financial elements” [<highlight style="bold">#3</highlight>] =</verbatim><verbatim format="linespecific"><highlight style="ital">{DTD: decimal pseudo-definition[2], Figure <xref refloc="xmLPmacro2orcamPLmx" type="number"/>}</highlight>
&lt;!ELEMENT open  (%Decimal;)&gt;
&lt;!ELEMENT high  (%Decimal;)&gt;
&lt;!ELEMENT low   (%Decimal;)&gt;
&lt;!ELEMENT close (%Decimal;)&gt;</verbatim><para><highlight style="ital">This macro is also defined in macro</highlight> #6 (Figure <xref refloc="xmLPmacro6orcamPLmx" type="number"/>)</para><para><highlight style="ital">This macro is invoked in file</highlight> #1 (Figure <xref refloc="xmLPfile1elifPLmx" type="number"/>)</para></figure>
      <para><highlight style="ital">Note: this shows how invocations (expansions) of one macro inside another are indicated and cross-referenced in the documentation.</highlight></para><para><highlight style="ital">Note:   this macro is defined in multiple sections that are concatenated in document order to produce the complete content of the macro.</highlight></para><para>The W3C XML Schema datatypes contain a suitable decimal type,
“xsd:decimal”, so the Schema equivalent is straightforward.</para><figure id="xmLPmacro4orcamPLmx" anchor="float"><verbatim format="linespecific"><highlight style="bold">xmLP Macro</highlight> “W3C XML Schema: financial elements” [<highlight style="bold">#4</highlight>] =</verbatim><verbatim format="linespecific">&lt;xsd:element name="<highlight style="bold">open</highlight>" type="<highlight style="bold">xsd:decimal</highlight>"/&gt;
&lt;xsd:element name="<highlight style="bold">high</highlight>" type="<highlight style="bold">xsd:decimal</highlight>"/&gt;
&lt;xsd:element name="<highlight style="bold">low</highlight>" type="<highlight style="bold">xsd:decimal</highlight>"/&gt;
&lt;xsd:element name="<highlight style="bold">close</highlight>" type="<highlight style="bold">xsd:decimal</highlight>"/&gt;</verbatim><para><highlight style="ital">This macro is also defined in macro</highlight> #7 (Figure <xref refloc="xmLPmacro7orcamPLmx" type="number"/>)</para><para><highlight style="ital">This macro is invoked in file</highlight> #3 (Figure <xref refloc="xmLPfile3elifPLmx" type="number"/>)</para></figure>
   </subsec1>
   <subsec1>
     <title>volume</title>
      <para>The “volume” element contains a non-negative integer value
(number of shares traded).  It also has a positive integer “multiplier”
attribute, since the volume is typically given in units of thousands of
shares.  As before, in the DTD the values are simply unconstrained text.</para>
      <figure id="xmLPmacro5orcamPLmx" anchor="float"><verbatim format="linespecific"><highlight style="bold">xmLP Macro</highlight> “DTD: integer pseudo-definitions” [<highlight style="bold">#5</highlight>] =</verbatim><verbatim format="linespecific">&lt;!ENTITY % NonNegativeInteger "#PCDATA"&gt;
&lt;!ENTITY % PositiveInteger "CDATA"&gt;</verbatim><para><highlight style="ital">This macro is invoked in macro</highlight> #6 (Figure <xref refloc="xmLPmacro6orcamPLmx" type="number"/>)</para></figure>
      <para>The DTD nonetheless allows a default value of ‘1’ to be defined
for the “multiplier” attribute, so that its use with the “volume” element is
optional.</para>
      <figure id="xmLPmacro6orcamPLmx" anchor="float"><verbatim format="linespecific"><highlight style="bold">xmLP Macro</highlight> “DTD: financial elements” [<highlight style="bold">#6</highlight>] =</verbatim><verbatim format="linespecific"><highlight style="ital">{DTD: integer pseudo-definitions[5], Figure <xref refloc="xmLPmacro5orcamPLmx" type="number"/>}</highlight>
&lt;!ELEMENT volume (%NonNegativeInteger;)&gt;
&lt;!ATTLIST volume
  multiplier %PositiveInteger; "1"&gt;</verbatim><para><highlight style="ital">This macro is also defined in macro</highlight> #3 (Figure <xref refloc="xmLPmacro3orcamPLmx" type="number"/>)</para><para><highlight style="ital">This macro is invoked in file</highlight> #1 (Figure <xref refloc="xmLPfile1elifPLmx" type="number"/>)</para></figure>
      <para>The W3C XML Schema data types contain the necessary integer data
types.  Although the Schema version is longer, it defines the same structure
for the “volume” element.</para>
      <figure id="xmLPmacro7orcamPLmx" anchor="float"><verbatim format="linespecific"><highlight style="bold">xmLP Macro</highlight> “W3C XML Schema: financial elements” [<highlight style="bold">#7</highlight>] =</verbatim><verbatim format="linespecific">&lt;xsd:element name="<highlight style="bold">volume</highlight>"&gt;<highlight style="bold"/>
  &lt;xsd:complexType&gt;<highlight style="bold"/>
    &lt;xsd:simpleContent&gt;<highlight style="bold"/>
      &lt;xsd:extension base="<highlight style="bold">xsd:nonNegativeInteger</highlight>"&gt;<highlight style="bold"/>
        &lt;xsd:attribute name="<highlight style="bold">multiplier</highlight>" default="<highlight style="bold">1</highlight>" type="<highlight style="bold">xsd:positiveInteger</highlight>"/&gt;<highlight style="bold"/>
      &lt;/xsd:extension&gt;<highlight style="bold"/>
    &lt;/xsd:simpleContent&gt;<highlight style="bold"/>
  &lt;/xsd:complexType&gt;<highlight style="bold"/>
&lt;/xsd:element&gt;</verbatim><para><highlight style="ital">This macro is also defined in macro</highlight> #4 (Figure <xref refloc="xmLPmacro4orcamPLmx" type="number"/>)</para><para><highlight style="ital">This macro is invoked in file</highlight> #3 (Figure <xref refloc="xmLPfile3elifPLmx" type="number"/>)</para></figure>
   </subsec1>
   <subsec1>
     <title>event</title>
      <para>The “event” element should contain no more than one each of the
elements “open”, “high”, “low”, “close”, and “volume”.  The order is not
important.  An “event” does not need to contain all of these elements, as
any of the values could be undefined or unavailable.  So each of the financial
elements occurs 0 or 1 times in an “event”, in any order.</para>
      <para>It is possible, but tedious,
to create an XML DTD rule that enumerates all of the possible content options
for “event”.  Instead, it is simpler to make the DTD stricter than the
W3C XML Schema, and have it enforce an (unnecessary) order on the financial
elements.</para>
      <figure id="xmLPmacro8orcamPLmx" anchor="float"><verbatim format="linespecific"><highlight style="bold">xmLP Macro</highlight> “DTD: event” [<highlight style="bold">#8</highlight>] =</verbatim><verbatim format="linespecific">&lt;!ELEMENT event (open?, high?, low?, close?, volume?)&gt;</verbatim><para><highlight style="ital">This macro is also defined in macro</highlight> #10 (Figure <xref refloc="xmLPmacro10orcamPLmx" type="number"/>)</para><para><highlight style="ital">This macro is invoked in file</highlight> #1 (Figure <xref refloc="xmLPfile1elifPLmx" type="number"/>)</para></figure>
      <para>The “event” element is also required to have a “date” attribute to
date the values that it contains.</para>
      <figure id="xmLPmacro9orcamPLmx" anchor="float"><verbatim format="linespecific"><highlight style="bold">xmLP Macro</highlight> “DTD: date pseudo-definition” [<highlight style="bold">#9</highlight>] =</verbatim><verbatim format="linespecific">&lt;!ENTITY % Date "CDATA"&gt;</verbatim><para><highlight style="ital">This macro is invoked in macro</highlight> #10 (Figure <xref refloc="xmLPmacro10orcamPLmx" type="number"/>)</para></figure>
      <figure id="xmLPmacro10orcamPLmx" anchor="float"><verbatim format="linespecific"><highlight style="bold">xmLP Macro</highlight> “DTD: event” [<highlight style="bold">#10</highlight>] =</verbatim><verbatim format="linespecific"><highlight style="ital">{DTD: date pseudo-definition[9], Figure <xref refloc="xmLPmacro9orcamPLmx" type="number"/>}</highlight>
&lt;!ATTLIST event
  date %Date; #REQUIRED&gt;</verbatim><para><highlight style="ital">This macro is also defined in macro</highlight> #8 (Figure <xref refloc="xmLPmacro8orcamPLmx" type="number"/>)</para><para><highlight style="ital">This macro is invoked in file</highlight> #1 (Figure <xref refloc="xmLPfile1elifPLmx" type="number"/>)</para></figure>
      <para>W3C XML Schema supports the “0 or 1 times each in any order” rule
using “xsd:all”.</para>   
      <figure id="xmLPmacro11orcamPLmx" anchor="float"><verbatim format="linespecific"><highlight style="bold">xmLP Macro</highlight> “W3C XML Schema: event” [<highlight style="bold">#11</highlight>] =</verbatim><verbatim format="linespecific">&lt;xsd:element name="<highlight style="bold">event</highlight>"&gt;<highlight style="bold"/>
  &lt;xsd:complexType&gt;<highlight style="bold"/>
    &lt;xsd:all&gt;<highlight style="bold"/>
      &lt;xsd:element ref="<highlight style="bold">open</highlight>"/&gt;<highlight style="bold"/>
      &lt;xsd:element ref="<highlight style="bold">high</highlight>"/&gt;<highlight style="bold"/>
      &lt;xsd:element ref="<highlight style="bold">low</highlight>"/&gt;<highlight style="bold"/>
      &lt;xsd:element ref="<highlight style="bold">close</highlight>"/&gt;<highlight style="bold"/>
      &lt;xsd:element ref="<highlight style="bold">volume</highlight>"/&gt;<highlight style="bold"/>
    &lt;/xsd:all&gt;<highlight style="bold"/>
    &lt;xsd:attribute name="<highlight style="bold">date</highlight>" use="<highlight style="bold">required</highlight>" type="<highlight style="bold">xsd:date</highlight>"/&gt;<highlight style="bold"/>
  &lt;/xsd:complexType&gt;<highlight style="bold"/>
&lt;/xsd:element&gt;</verbatim><para><highlight style="ital">This macro is invoked in file</highlight> #3 (Figure <xref refloc="xmLPfile3elifPLmx" type="number"/>)</para></figure>
    </subsec1>
    <subsec1>
      <title>timeSeries</title>
      <para>To represent a time series, a number of events are contained within
a “timeSeries” element.  A time series can contain any number of events, even zero.
The dates of the events within a time series must be unique, but neither of the
schema technologies used here can enforce that condition.</para>    
      <figure id="xmLPmacro12orcamPLmx" anchor="float"><verbatim format="linespecific"><highlight style="bold">xmLP Macro</highlight> “DTD: timeSeries” [<highlight style="bold">#12</highlight>] =</verbatim><verbatim format="linespecific">&lt;!ELEMENT timeSeries (event*)&gt;</verbatim><para><highlight style="ital">This macro is invoked in file</highlight> #1 (Figure <xref refloc="xmLPfile1elifPLmx" type="number"/>)</para></figure>
      <figure id="xmLPmacro13orcamPLmx" anchor="float"><verbatim format="linespecific"><highlight style="bold">xmLP Macro</highlight> “W3C XML Schema: timeSeries” [<highlight style="bold">#13</highlight>] =</verbatim><verbatim format="linespecific">&lt;xsd:element name="<highlight style="bold">timeSeries</highlight>"&gt;<highlight style="bold"/>
  &lt;xsd:complexType&gt;<highlight style="bold"/>
    &lt;xsd:sequence&gt;<highlight style="bold"/>
      &lt;xsd:element ref="<highlight style="bold">event</highlight>" minOccurs="<highlight style="bold">0</highlight>" maxOccurs="<highlight style="bold">unbounded</highlight>"/&gt;<highlight style="bold"/>
    &lt;/xsd:sequence&gt;<highlight style="bold"/>
  &lt;/xsd:complexType&gt;<highlight style="bold"/>
&lt;/xsd:element&gt;</verbatim><para><highlight style="ital">This macro is invoked in file</highlight> #3 (Figure <xref refloc="xmLPfile3elifPLmx" type="number"/>)</para></figure>
    </subsec1>
    <subsec1>
      <title>DTD Source Files</title>
      <para>With all of its required sections now explained, the DTD is
assembled from the component macros as follows.</para>
      <figure id="xmLPfile1elifPLmx" anchor="float"><verbatim format="linespecific"><highlight style="bold">xmLP File</highlight> [<highlight style="bold">#1</highlight>]: src/timeseries.dtd =</verbatim><verbatim format="linespecific">&lt;?xml version="1.0" encoding="utf-8"?&gt;
<highlight style="ital">{DTD: financial elements[3,6], Figures <xref refloc="xmLPmacro3orcamPLmx" type="number"/>, <xref refloc="xmLPmacro6orcamPLmx" type="number"/>}</highlight>
<highlight style="ital">{DTD: event[8], Figure <xref refloc="xmLPmacro8orcamPLmx" type="number"/>}</highlight>
<highlight style="ital">{DTD: timeSeries[12], Figure <xref refloc="xmLPmacro12orcamPLmx" type="number"/>}</highlight></verbatim></figure>
      <para><highlight style="ital">Note: this shows how xmLP file macro definitions are “woven” into the documentation.  These define the source files that are generated during “tangling”.</highlight></para><para>This produces the following source file:</para>
    <figure anchor="float"><verbatim format="linespecific">&lt;?xml version="1.0" encoding="utf-8"?&gt;


&lt;!ENTITY % Decimal "#PCDATA"&gt;

&lt;!ELEMENT open  (%Decimal;)&gt;
&lt;!ELEMENT high  (%Decimal;)&gt;
&lt;!ELEMENT low   (%Decimal;)&gt;
&lt;!ELEMENT close (%Decimal;)&gt;


&lt;!ENTITY % NonNegativeInteger "#PCDATA"&gt;
&lt;!ENTITY % PositiveInteger "CDATA"&gt;

&lt;!ELEMENT volume (%NonNegativeInteger;)&gt;
&lt;!ATTLIST volume
  multiplier %PositiveInteger; "1"&gt;


&lt;!ELEMENT event (open?, high?, low?, close?, volume?)&gt;


&lt;!ENTITY % Date "CDATA"&gt;

&lt;!ATTLIST event
  date %Date; #REQUIRED&gt;


&lt;!ELEMENT timeSeries (event*)&gt;
</verbatim></figure><para>The sample instance file using the DTD (and containing just a
single event) requires an appropriate “DOCTYPE” declaration.</para>
      <figure id="xmLPfile2elifPLmx" anchor="float"><verbatim format="linespecific"><highlight style="bold">xmLP File</highlight> [<highlight style="bold">#2</highlight>]: src/timeseries-dtd.xml =</verbatim><verbatim format="linespecific">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!DOCTYPE timeSeries SYSTEM "timeseries.dtd"&gt;
&lt;timeSeries&gt;<highlight style="bold"/>
  <highlight style="ital">{Time Series Event Instance[1], Figure <xref refloc="xmLPmacro1orcamPLmx" type="number"/>}</highlight><highlight style="bold"/>
&lt;/timeSeries&gt;</verbatim></figure>
    <para>This produces the following source file:</para>
   <figure anchor="float"><verbatim format="linespecific">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!DOCTYPE timeSeries SYSTEM "timeseries.dtd"&gt;
&lt;timeSeries&gt;
  &lt;event date="2002-02-20"&gt;
    &lt;open&gt;85.70&lt;/open&gt;
    &lt;high&gt;92.10&lt;/high&gt;
    &lt;low&gt;81.37&lt;/low&gt;
    &lt;close&gt;86.05&lt;/close&gt;
    &lt;volume multiplier="1000"&gt;811786&lt;/volume&gt;
  &lt;/event&gt;
&lt;/timeSeries&gt;</verbatim></figure><para><highlight style="ital">Note: the tangled source file was inserted into this document automatically using an <acronym.grp><acronym>XSLT</acronym><expansion>Extensible Stylesheet Language Transformations</expansion></acronym.grp> script.</highlight></para></subsec1>
    <subsec1>
      <title>W3C XML Schema Source Files</title>
      <para>The W3C XML Schema is assembled from the component macros
as follows.</para>
      <figure id="xmLPfile3elifPLmx" anchor="float"><verbatim format="linespecific"><highlight style="bold">xmLP File</highlight> [<highlight style="bold">#3</highlight>]: src/timeseries.xsd =</verbatim><verbatim format="linespecific">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;<highlight style="bold"/>
  <highlight style="ital">{W3C XML Schema: financial elements[4,7], Figures <xref refloc="xmLPmacro4orcamPLmx" type="number"/>, <xref refloc="xmLPmacro7orcamPLmx" type="number"/>}</highlight><highlight style="bold"/>
  <highlight style="ital">{W3C XML Schema: event[11], Figure <xref refloc="xmLPmacro11orcamPLmx" type="number"/>}</highlight><highlight style="bold"/>
  <highlight style="ital">{W3C XML Schema: timeSeries[13], Figure <xref refloc="xmLPmacro13orcamPLmx" type="number"/>}</highlight><highlight style="bold"/>
&lt;/xsd:schema&gt;</verbatim></figure>
      <para>This produces the following source file:</para>
    <figure anchor="float"><verbatim format="linespecific">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  &lt;xsd:element name="open" type="xsd:decimal"/&gt;
  &lt;xsd:element name="high" type="xsd:decimal"/&gt;
  &lt;xsd:element name="low" type="xsd:decimal"/&gt;
  &lt;xsd:element name="close" type="xsd:decimal"/&gt;
  &lt;xsd:element name="volume"&gt;
    &lt;xsd:complexType&gt;
      &lt;xsd:simpleContent&gt;
        &lt;xsd:extension base="xsd:nonNegativeInteger"&gt;
          &lt;xsd:attribute name="multiplier" default="1" type="xsd:positiveInteger"/&gt;
        &lt;/xsd:extension&gt;
      &lt;/xsd:simpleContent&gt;
    &lt;/xsd:complexType&gt;
  &lt;/xsd:element&gt;
  &lt;xsd:element name="event"&gt;
    &lt;xsd:complexType&gt;
      &lt;xsd:all&gt;
        &lt;xsd:element ref="open"/&gt;
        &lt;xsd:element ref="high"/&gt;
        &lt;xsd:element ref="low"/&gt;
        &lt;xsd:element ref="close"/&gt;
        &lt;xsd:element ref="volume"/&gt;
      &lt;/xsd:all&gt;
      &lt;xsd:attribute name="date" use="required" type="xsd:date"/&gt;
    &lt;/xsd:complexType&gt;
  &lt;/xsd:element&gt;
  &lt;xsd:element name="timeSeries"&gt;
    &lt;xsd:complexType&gt;
      &lt;xsd:sequence&gt;
        &lt;xsd:element ref="event" minOccurs="0" maxOccurs="unbounded"/&gt;
      &lt;/xsd:sequence&gt;
    &lt;/xsd:complexType&gt;
  &lt;/xsd:element&gt;
&lt;/xsd:schema&gt;</verbatim></figure><para>The sample instance file using the W3C XML Schema (and containing just a
single event) requires an appropriate “schemaLocation” declaration (in this case a “noNamespaceSchemaLocation” declaration).  The “xmlns:xsi” declaration is suppressed for brevity, but generated in the actual source file.</para>    
      <figure id="xmLPfile4elifPLmx" anchor="float"><verbatim format="linespecific"><highlight style="bold">xmLP File</highlight> [<highlight style="bold">#4</highlight>]: src/timeseries-schema.xml =</verbatim><verbatim format="linespecific">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;timeSeries xsi:noNamespaceSchemaLocation="timeseries.xsd"&gt;<highlight style="bold"/>
  <highlight style="ital">{Time Series Event Instance[1], Figure <xref refloc="xmLPmacro1orcamPLmx" type="number"/>}</highlight><highlight style="bold"/>
&lt;/timeSeries&gt;</verbatim></figure>
    <para>This produces the following source file:</para>
   <figure anchor="float"><verbatim format="linespecific">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;timeSeries xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="timeseries.xsd"&gt;
  &lt;event date="2002-02-20"&gt;
    &lt;open&gt;85.70&lt;/open&gt;
    &lt;high&gt;92.10&lt;/high&gt;
    &lt;low&gt;81.37&lt;/low&gt;
    &lt;close&gt;86.05&lt;/close&gt;
    &lt;volume multiplier="1000"&gt;811786&lt;/volume&gt;
  &lt;/event&gt;
&lt;/timeSeries&gt;</verbatim></figure></subsec1><subsec1><title>Summary</title><para>What you have read in this section is a literate program which defines and describes the DTD and W3C XML Schema fragments required to handle a real-world problem.  The code fragments in the macros appear within a human-readable context that quickly clarifies what those fragments do, why they are needed, and what their limitations are.  Being able to view DTD fragments beside their equivalent Schema fragments makes it easy to compare the two approaches in detail.</para></subsec1>
  </section>
<section id="section-using-xmLP">
      <title>Using xmLP</title>
      
      
    <subsec1><title>xmLP Goals &amp; Approach</title><para>Having established the nature of a literate program, the way in which the “xmLP” tool supports <acronym>LitProg</acronym> can be described.  Traditional <acronym>LitProg</acronym> tools provide the following:</para><seqlist number="arabic"><li><para>A complete (but tool-specific) markup language for literate programs, including both code and documentation sections;</para></li><li><para>(Optionally) One or more code section markups for specific programming languages, or for other source file formats;</para></li><li><para>The ability to “tangle” literate programs (assemble code sections) to generate the source files;</para></li><li><para>The ability to “weave” literate programs into a final documentation format.</para></li></seqlist><para>The advent of XML made it less attractive and less necessary to define and support custom markup languages for literate documents.  To take advantage of XML, xmLP takes the following approach:</para><seqlist number="arabic"><li><para>Rather than define its own complete document markup, xmLP only defines a handful of XML elements which are intended to be used in conjunction with any suitable XML document markup, e.g. <acronym>XHTML</acronym> or DocBook;</para></li><li><para>In order to keep xmLP from being constrained to a specific programming language, xmLP follows the traditional <acronym>LitProg</acronym> tools “FunnelWeb” and “noweb” (among others).  These tools treat all code as text.  This can be an advantage when you need to include a programming language or other file format that is not supported by your <acronym>LitProg</acronym> tool of choice.  xmLP adds a slight extra — support for well-formed XML fragments.  These make it easier to create correctly generate well-formed XML, by removing the risk of unmatched open or close tags;</para></li><li><para>xmLP does not weave literate programs into a final documentation format as traditional <acronym>LitProg</acronym> tools do.  Instead, the xmLP weaver adds just the contextual information needed to allow an <acronym>XSLT</acronym> stylesheet to format the code sections in the literate program.</para></li></seqlist><para>Primarily, xmLP provides the <highlight style="bold">business logic</highlight> to deal with code macros, both for tangling and weaving.  End users can concentrate on writing stylesheets that define the look and layout of their documentation, without having to worry about the semantics of macros and macro invocation, and without having to worry about building cross-reference information for the macros.  These things are handled by xmLP.</para></subsec1><subsec1><title>Defining a macro</title><para>So, what does the xmLP markup look like?  In the literate document from which this paper was woven, the macro corresponding to Figure <xref refloc="xmLPmacro2orcamPLmx" type="number"/> is actually written as</para>
      <figure anchor="float"><verbatim format="linespecific">&lt;lp:macro lp:usage="<highlight style="bold">once</highlight>" lp:final="<highlight style="bold">true</highlight>"&gt;<highlight style="bold"/>
  &lt;lp:name&gt;<highlight style="bold">DTD: decimal pseudo-definition</highlight>&lt;/lp:name&gt;<highlight style="bold"/>
  &lt;lp:text&gt;<highlight style="bold">
&lt;!ENTITY % Decimal "#PCDATA"&gt;
</highlight>&lt;/lp:text&gt;<highlight style="bold"/>
&lt;/lp:macro&gt;</verbatim></figure>
      <para>xmLP defines the following elements and attributes for creating macros. As mentioned previously,  xmLP elements and attribute definitions are added to a DTD/Schema/etc. to make them available directly in the authoring of a document. A fragment DTD containing the complete list of xmLP elements and attributes is included in the appendix in Section <xref refloc="fragment-dtd" type="number"/>.</para><deflist><def.item><def.term><highlight style="bold">lp:macro</highlight></def.term><def><para>element: Indicates the definition of an xmLP macro.</para></def></def.item><def.item><def.term><highlight style="bold">lp:usage</highlight></def.term><def><para>attribute: One of “never” or “once” (the default) or “multiple”.  Used to indicate how often the macro is to be invoked (used).  This proves to be a valuable quality-control (sanity checking) measure, and is taken from “FunnelWeb”.</para></def></def.item><def.item><def.term><highlight style="bold">lp:final</highlight></def.term><def><para>attribute: One of “true” (the default) or “false”.  If true, only this macro definition can have the given “lp:name”.  If false, all macro definitions with the same “lp:name” are concatenated in document order to fully define the macro.  Once again, taken from “FunnelWeb”.</para></def></def.item><def.item><def.term><highlight style="bold">lp:name</highlight></def.term><def><para>element: The name of the macro being defined.  In principle, the name may contain XML elements, so that MathML expressions and the like can be used in macro names.  In practice, xmLP currently applies the XPath “normalize-space” function to the macro name to generate a simple text name that is then used to decide whether two macro definitions have the same macro name or not.  This is not ideal, but sufficiently good for most purposes.</para></def></def.item><def.item><def.term><highlight style="bold">lp:text</highlight></def.term><def><para>element: Indicates a plain text component of the macro definition.</para></def></def.item></deflist></subsec1><subsec1><title>Invoking a macro</title><para>Invoking (calling or expanding) a macro is done with another xmLP element, “lp:invoke”. This element stands in place of the macro being called, and is entirely replaced by it during tangling (assembly of the generated source code files).

Taking as an example the macro defined in Figures <xref refloc="xmLPmacro3orcamPLmx" type="number"/> and <xref refloc="xmLPmacro6orcamPLmx" type="number"/>, this macro is written over <highlight style="bold">two</highlight> concatenated definitions (note that “lp:final” is set to false), and uses “lp:invoke” to insert the contents of the macro defined in Figure <xref refloc="xmLPmacro5orcamPLmx" type="number"/>:</para><figure anchor="float"><verbatim format="linespecific">&lt;lp:macro lp:usage="<highlight style="bold">once</highlight>" lp:final="<highlight style="bold">false</highlight>"&gt;<highlight style="bold"/>
  &lt;lp:name&gt;<highlight style="bold">DTD: financial elements</highlight>&lt;/lp:name&gt;<highlight style="bold"/>
  &lt;lp:text&gt;<highlight style="bold"/>&lt;lp:invoke&gt;
  &lt;lp:name&gt;<highlight style="bold">DTD: decimal pseudo-definition</highlight>&lt;/lp:name&gt;
&lt;/lp:invoke&gt;<highlight style="bold">
&lt;!ELEMENT open  (%Decimal;)&gt;
&lt;!ELEMENT high  (%Decimal;)&gt;
&lt;!ELEMENT low   (%Decimal;)&gt;
&lt;!ELEMENT close (%Decimal;)&gt;
</highlight>
  &lt;/lp:text&gt;<highlight style="bold"/>
&lt;/lp:macro&gt;</verbatim></figure><figure anchor="float"><verbatim format="linespecific">&lt;lp:macro lp:usage="<highlight style="bold">once</highlight>" lp:final="<highlight style="bold">false</highlight>"&gt;<highlight style="bold"/>
  &lt;lp:name&gt;<highlight style="bold">DTD: financial elements</highlight>&lt;/lp:name&gt;<highlight style="bold"/>
  &lt;lp:text&gt;<highlight style="bold"/>&lt;lp:invoke&gt;
  &lt;lp:name&gt;<highlight style="bold">DTD: integer pseudo-definitions</highlight>&lt;/lp:name&gt;
&lt;/lp:invoke&gt;<highlight style="bold">
&lt;!ELEMENT volume (%NonNegativeInteger;)&gt;
&lt;!ATTLIST volume
  multiplier %PositiveInteger; "1"&gt;
</highlight>
  &lt;/lp:text&gt;<highlight style="bold"/>
&lt;/lp:macro&gt;</verbatim></figure><deflist><def.item><def.term><highlight style="bold">lp:invoke</highlight></def.term><def><para>element: Invokes an xmLP macro by name, replacing the “lp:invoke” element completely with the macro contents.</para></def></def.item></deflist></subsec1><subsec1><title>XML macros</title><para>As well as plain text, xmLP macros can contain well-formed XML using “lp:xml”.  As previously mentioned, well-formed XML fragments remove the risk of unmatched open or close tags.  You can use plain text fragments (“lp:text”) to generate XML if you want, and it is sometimes useful to do so, but you take the risk of having unmatched tags in your generated XML source files.  The following example corresponds to the output shown in Figure <xref refloc="xmLPmacro1orcamPLmx" type="number"/>.</para>
<figure anchor="float"><verbatim format="linespecific">&lt;lp:macro lp:usage="<highlight style="bold">multiple</highlight>" lp:final="<highlight style="bold">true</highlight>"&gt;<highlight style="bold"/>
  &lt;lp:name&gt;<highlight style="bold">Time Series Event Instance</highlight>&lt;/lp:name&gt;<highlight style="bold"/>
  &lt;lp:xml&gt;<highlight style="bold"/>
    &lt;event date="<highlight style="bold">2002-02-20</highlight>"&gt;<highlight style="bold"/>
      &lt;open&gt;<highlight style="bold">85.70</highlight>&lt;/open&gt;<highlight style="bold"/>
      &lt;high&gt;<highlight style="bold">92.10</highlight>&lt;/high&gt;<highlight style="bold"/>
      &lt;low&gt;<highlight style="bold">81.37</highlight>&lt;/low&gt;<highlight style="bold"/>
      &lt;close&gt;<highlight style="bold">86.05</highlight>&lt;/close&gt;<highlight style="bold"/>
      &lt;volume multiplier="<highlight style="bold">1000</highlight>"&gt;<highlight style="bold">811786</highlight>&lt;/volume&gt;<highlight style="bold"/>
    &lt;/event&gt;<highlight style="bold"/>
  &lt;/lp:xml&gt;<highlight style="bold"/>
&lt;/lp:macro&gt;</verbatim></figure><deflist><def.item><def.term><highlight style="bold">lp:xml</highlight></def.term><def><para>element: Indicates a well-formed XML component of the macro definition.</para></def></def.item></deflist></subsec1><subsec1><title>Defining output source files</title><para>xmLP uses the “lp:file”  element to distinguish top-level macros that define output source files (there can only be one such macro for each output source file). These file macros have a file name rather than a macro name. Note that “lp:file” macros cannot be invoked by other macros. Namespaces are supported by xmLP using “lp:namespace”, as in the following example which corresponds to the output shown in Figure <xref refloc="xmLPfile3elifPLmx" type="number"/>.</para>
<figure anchor="float"><verbatim format="linespecific">&lt;lp:file lp:filename="<highlight style="bold">src/timeseries.xsd</highlight>"&gt;<highlight style="bold"/>
  &lt;lp:namespace lp:value="<highlight style="bold">http://www.w3.org/2001/XMLSchema</highlight>" lp:prefix="<highlight style="bold">xsd</highlight>"/&gt;<highlight style="bold"/>
  &lt;lp:text&gt;<highlight style="bold">
&lt;?xml version="1.0" encoding="utf-8"?&gt;

</highlight>&lt;/lp:text&gt;<highlight style="bold"/>
  &lt;lp:xml&gt;<highlight style="bold"/>
    &lt;xsd:schema&gt;<highlight style="bold"/>&lt;lp:invoke&gt;
  &lt;lp:name&gt;<highlight style="bold">W3C XML Schema: financial elements</highlight>&lt;/lp:name&gt;
&lt;/lp:invoke&gt;<highlight style="bold"/>&lt;lp:invoke&gt;
  &lt;lp:name&gt;<highlight style="bold">W3C XML Schema: event</highlight>&lt;/lp:name&gt;
&lt;/lp:invoke&gt;<highlight style="bold"/>&lt;lp:invoke&gt;
  &lt;lp:name&gt;<highlight style="bold">W3C XML Schema: timeSeries</highlight>&lt;/lp:name&gt;
&lt;/lp:invoke&gt;<highlight style="bold"/>
    &lt;/xsd:schema&gt;<highlight style="bold"/>
  &lt;/lp:xml&gt;<highlight style="bold"/>
&lt;/lp:file&gt;</verbatim></figure><deflist><def.item><def.term><highlight style="bold">lp:file</highlight></def.term><def><para>element: Indicates the definition of an xmLP <highlight style="bold">file macro</highlight>.</para></def></def.item><def.item><def.term><highlight style="bold">lp:filename</highlight></def.term><def><para>attribute: The file name (or path) of the file being defined.</para></def></def.item><def.item><def.term><highlight style="bold">lp:namespace</highlight></def.term><def><para>element: Indicates that a namespace declaration should be added to the tangled XML.</para></def></def.item><def.item><def.term><highlight style="bold">lp:prefix</highlight></def.term><def><para>attribute: The namespace prefix to use.</para></def></def.item><def.item><def.term><highlight style="bold">lp:value</highlight></def.term><def><para>attribute: The namespace identifier (typically a URI).</para></def></def.item></deflist><para>To support W3C XML Schema, it is sometimes necessary to specify a Schema location using “lp:schemaLocation”, as in the following example which corresponds to the output shown in Figure <xref refloc="xmLPfile4elifPLmx" type="number"/>.</para>
<figure anchor="float"><verbatim format="linespecific">&lt;lp:file lp:filename="<highlight style="bold">src/timeseries-schema.xml</highlight>"&gt;<highlight style="bold"/>
  &lt;lp:schemaLocation lp:namespace="<highlight style="bold"/>" lp:location="<highlight style="bold">timeseries.xsd</highlight>"/&gt;<highlight style="bold"/>
  &lt;lp:text&gt;<highlight style="bold">
&lt;?xml version="1.0" encoding="utf-8"?&gt;

</highlight>&lt;/lp:text&gt;<highlight style="bold"/>
  &lt;lp:xml&gt;<highlight style="bold"/>
    &lt;timeSeries&gt;<highlight style="bold"/>&lt;lp:invoke&gt;
  &lt;lp:name&gt;<highlight style="bold">Time Series Event Instance</highlight>&lt;/lp:name&gt;
&lt;/lp:invoke&gt;<highlight style="bold"/>
    &lt;/timeSeries&gt;<highlight style="bold"/>
  &lt;/lp:xml&gt;<highlight style="bold"/>
&lt;/lp:file&gt;</verbatim></figure><deflist><def.item><def.term><highlight style="bold">lp:schemaLocation</highlight></def.term><def><para>element: Indicates that a (W3C XML) Schema location declaration should be added to the tangled XML.</para></def></def.item><def.item><def.term><highlight style="bold">lp:namespace</highlight></def.term><def><para>attribute: The namespace identifier (typically a URI).  Can be empty.</para></def></def.item><def.item><def.term><highlight style="bold">lp:location</highlight></def.term><def><para>attribute: The Schema location URI.</para></def></def.item></deflist></subsec1><subsec1><title>Implementation of xmLP</title><para>
        
        The current implementation of xmLP (version 1.1) is written as 600 lines of <acronym>XSLT</acronym> (plus stylesheets for particular formats like <acronym>XHTML</acronym>).  This may change in future
implementations.  A potential improvement to xmLP would be to introduce parameterized macros (in the manner of “FunnelWeb”), but it is yet to be decided whether this is best done in <acronym>XSLT</acronym> or in a more general purpose programming language.</para></subsec1></section>
    <section>
      <title>Conclusion</title>
      <para>
        This paper has introduced literate programming, and indeed this paper is a literate program itself.  It has demonstrated how programs (and other source files) can be defined within the natural flow of a human-readable document, rather than in the flow defined by a compiler.  It has also introduced a simple <acronym>LitProg</acronym> tool, xmLP, which can be used to turn any XML document into a literate document.</para><para>The source files for this paper will be available at<verbatim format="linespecific">http://xmLP.sourceforge.net/2002/extreme/</verbatim></para>
    </section><section id="fragment-dtd"><title>Appendix — a fragment DTD for xmLP</title><para>This DTD fragment is non-normative.</para>
    <figure anchor="float"><verbatim format="linespecific">&lt;?xml version='1.0' encoding='UTF-8' ?&gt;

&lt;!-- PUBLIC "+//IDN xmLP.org//DTD Sample Module for xmLP//EN" --&gt;

&lt;!-- The name of an "xmLP" macro. --&gt;
&lt;!ELEMENT lp:name ANY&gt;

&lt;!-- An invocation of an "xmLP" macro. --&gt;
&lt;!ELEMENT lp:invoke (lp:name)&gt;

&lt;!-- Text within an "xmLP" macro. --&gt;
&lt;!ELEMENT lp:text (#PCDATA | lp:invoke)*&gt;

&lt;!-- Balanced XML within an "xmLP" macro. --&gt;
&lt;!ELEMENT lp:xml ANY&gt;

&lt;!-- An "xmLP" macro. --&gt;
&lt;!ELEMENT lp:macro (lp:name , lp:namespace* , (lp:text | lp:xml)*)&gt;
&lt;!ATTLIST lp:macro lp:usage  (never | once | multiple )  'once'
                   lp:final  (true | false )  'true' &gt;

&lt;!-- An "xmLP" namespace declaration. --&gt;
&lt;!ELEMENT lp:namespace EMPTY&gt;
&lt;!ATTLIST lp:namespace lp:prefix NMTOKEN  #REQUIRED
                       lp:value  CDATA    #REQUIRED &gt;

&lt;!-- An "xmLP" schemaLocation declaration. --&gt;
&lt;!ELEMENT lp:schemaLocation EMPTY&gt;
&lt;!ATTLIST lp:schemaLocation lp:namespace CDATA #REQUIRED
                            lp:location CDATA #REQUIRED &gt;

&lt;!-- An "xmLP" output file. --&gt;
&lt;!ELEMENT lp:file ((lp:namespace | lp:schemaLocation)* , (lp:text | lp:xml)*)&gt;
&lt;!ATTLIST lp:file lp:filename CDATA  #REQUIRED &gt;

&lt;!-- "xmLP" block elements. --&gt;
&lt;!ENTITY % lpBlock "lp:macro | lp:file"&gt;
</verbatim></figure></section></body>
<rear><bibliog><bibitem id="bib-lp-www"><bib>LP WWW</bib><pub>Literate Programming, http://www.literateprogramming.com/, http://www.loria.fr/services/tex/english/litte.html</pub></bibitem><bibitem id="bib-knuth-www"><bib>Knuth WWW</bib><pub>Donald Knuth, http://www-cs-faculty.stanford.edu/~knuth/</pub></bibitem><bibitem id="bib-knuth-92"><bib>Knuth 92</bib>
<pub>“Literate Programming” by Donald Knuth, 1992, ISBN 0-937073-80-6, http://www-cs-faculty.stanford.edu/~knuth/lp.html</pub></bibitem><bibitem id="bib-cweb-www"><bib>CWEB WWW</bib><pub>CWEB [LitProg tool], http://sunburn.stanford.edu/~knuth/cweb.html</pub></bibitem><bibitem id="bib-fweb-www"><bib>FWEB WWW</bib><pub>FWEB [LitProg tool], http://w3.pppl.gov/~krommes/fweb_toc.html</pub></bibitem><bibitem id="bib-noweb-www"><bib>noweb WWW</bib><pub>noweb [LitProg tool], http://www.eecs.harvard.edu/~nr/noweb/#top</pub></bibitem><bibitem id="bib-funnelweb-www"><bib>FunnelWeb WWW</bib><pub>FunnelWeb [LitProg tool], http://www.ross.net/funnelweb/</pub></bibitem><bibitem id="bib-sweb-www"><bib>SWEB WWW</bib><pub>SWEB [LitProg tool], http://tigger.uic.edu/~cmsmcq/tech/sweb/sweb.html</pub></bibitem><bibitem id="bib-xmLP-www"><bib>xmLP WWW</bib><pub>xmLP [LitProg tool], http://xmLP.sourceforge.net/</pub></bibitem><bibitem id="bib-xml-litprog-l"><bib>xml-litprog-l</bib><pub>xml-litprog-l [mailing list], http://groups.yahoo.com/group/xml-litprog-l/</pub></bibitem></bibliog></rear></paper>