title: How can I generate basic documentation from a Relax NG Schema
body: <p>I'm trying to generate very simple documentation from the annotations in a Relax NG XML Schema. For example, given the following Relax NG:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"&gt;
      &lt;start&gt;
          &lt;element name="topNode"&gt;
              &lt;ref name="topNode-ref"/&gt;
          &lt;/element&gt;
      &lt;/start&gt;
  
      &lt;define name="topNode-ref"&gt;
          &lt;a:documentation&gt;This is the top of the doc.&lt;/a:documentation&gt;
          &lt;oneOrMore&gt;
              &lt;element name="level1"&gt;
                  &lt;ref name="level1-ref"/&gt;
              &lt;/element&gt;
          &lt;/oneOrMore&gt;
      &lt;/define&gt;
  
      &lt;define name="level1-ref"&gt;
          &lt;a:documentation&gt;Here's some notes about level1.&lt;/a:documentation&gt;
          &lt;attribute name="att1"&gt;
              &lt;a:documentation&gt;Details about att1.&lt;/a:documentation&gt;
          &lt;/attribute&gt;
          &lt;element name="subLevel2"&gt;
              &lt;ref name="subLevel2-ref"/&gt;
          &lt;/element&gt;
      &lt;/define&gt;
  
      &lt;define name="subLevel2-ref"&gt;
          &lt;a:documentation&gt;Notes on subLevel2.&lt;/a:documentation&gt;
          &lt;attribute name="subAtt"/&gt;
          &lt;zeroOrMore&gt;
              &lt;element name="subLevel3"&gt;
                  &lt;ref name="subLevel3-ref"/&gt;
              &lt;/element&gt;
          &lt;/zeroOrMore&gt;
      &lt;/define&gt;
  
      &lt;define name="subLevel3-ref"&gt;
          &lt;a:documentation&gt;And here is subLevel3.&lt;/a:documentation&gt;
          &lt;attribute name="subSubAtt"/&gt;
      &lt;/define&gt;
  &lt;/grammar&gt;
  </code></pre>
  
  <p>Which would be used to valid an XML file like:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;topNode&gt;
      &lt;level1 att1="some test"&gt;
          &lt;subLevel2 subAtt="more text"&gt;&lt;/subLevel2&gt;
      &lt;/level1&gt;
  
      &lt;level1 att1="quick"&gt;
          &lt;subLevel2 subAtt="brown"&gt;
              &lt;subLevel3 subSubAtt="fox"&gt;&lt;/subLevel3&gt;
          &lt;/subLevel2&gt;
      &lt;/level1&gt;   
  &lt;/topNode&gt;
  </code></pre>
  
  <p>I'd like to be able to produce documentation that lists the basic XPath to each element/attribute and then display any corresponding documentation annotations. For example:</p>
  
  <pre><code>/topNode
  This is the top of the doc.
  
  /topNode/level1
  Here's some notes about level1
  
  /topNode/level1/@att1
  Details about att1.
  
  etc...
  </code></pre>
  
  <p>Eventually, I'll add in more documentation about "zeroOrMore", possible data types, etc... but I need to get this first step solved first.</p>
  
  <p>I've found the <a href="http://techquila.com/tech/relax-ng-tools/" rel="nofollow">Techquila RELAX-NG Documentation Tools</a>. I've played around with the rng to docbook stylesheet, but it don't do what I'm looking for. It just lists elements individually with no details about the XPath as far as I can tell. I don't see how I can use it as a starting point to get the output I'm after.</p>
  
  <p>Is it possible (and if so, how?) to produce this type of documentation output with XSLT given the RelaxNG example provided?</p>
  
  <p>While XSLT would be ideal, it's not a requirement. I'm open for anything that gets the job done. </p>