Processing XML documentation
Tuesday, 21 December 2010
Article Index
Processing XML documentation
XSL has loops
Documentation tools

Banner

 

Slightly more complicated is retrieving the summary text corresponding to MyMethod:

<h3>
Method:
<xsl:value-of select=
  'doc/members/member
     [@name="M:WindowsFormsApplication1.
         Form1.MyMethod(System.Int32,
              System.String)"]'/>
</h3>

In this case the XPath statement is complicated because of the need to quote the entire name of the member – but that’s all. The form of the selector just picks out all of the member tags but the predicate that follows narrows this selection down to the one with a name attribute equal to the quoted string.

Finally we bring the web page to a close:

   </body>
  </html>
</xsl:template>
</xsl:stylesheet>

If you now load the original XML file into a browser that supports XSL, i.e. any modern browser, it will be transformed by the XSL file assuming they are both stored in the same directory.

The complete listing of the XSL file is:

<?xml version="1.0"?>
 <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/
                         XSL/Transform">
  <xsl:template match="/">
   <html>
    <body>
     <h1>XSL formatted XML help</h1>
     <hr/>
     <h2>
      Assembly name:
      <xsl:value-of select=
                    "doc/assembly/name"/>
    </h2>
    <h3>
      Method:
      <xsl:value-of select=
       'doc/members/member
       [@name="M:WindowsFormsApplication1.
         Form1.MyMethod(
        System.Int32,System.String)"]'/>
    </h3>
   </body>
  </html>
 </xsl:template>
</xsl:stylesheet>

The result can be seen below:

 

XSL

 

XSL Loops

Of course in a real application you wouldn’t be quoting the name of each member in the way described above unless it was a very special member that needed individual attention. What is needed is some sort of automatic processing of each class and each method to generate documentation in a standard format. The good news is that XLS has the basic facilities of a processing language.

In most cases members would be processed using an XLS for loop something like:

<table border="2">
 <tbody>
  <tr>
   <td>
    <b>Member</b>
   </td>
   <td>
    <b>Summary</b>
   </td>
  </tr>
   <xsl:for-each
            select="doc/members/member">
   <tr>
    <td>
     <xsl:value-of select="@name"/>
    </td>
    <td>
     <xsl:value-of select="summary"/>
    </td>
   </tr>
  </xsl:for-each>
 </tbody>
</table>

In this case additional HTML has been supplied to build a table of members and names but the same sort of general technique can be used to construct other presentations. Notice the way that the for-each construct repeats for each node in the selected set and notice that within the loop the XSL XPath selections start from the currently selected node in the for loop.

The overall result of the XSL transformation can be seen below

table


Banner

<ASIN:0596007647>



Last Updated ( Tuesday, 21 December 2010 )
 
 

   
RSS feed of all content
I Programmer - full contents
Copyright © 2014 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.