[Mono-list] Help needed with XSLT transformations
(documentation browser)
Scott Bronson
bronson@rinspin.com
14 Oct 2002 02:47:20 -0700
--=-D6KG3KbByjBKQU8DxRPU
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Crud! Who puts the attach button right next to the send button?!
Where did the mscorlib.xml file come from? Is there any chance we can
add the class summaries to it? It will be a disaster if I need to open
each individual class.xml file and read the summaries when generating
index pages.
Here are the attachments. Put these in monodoc/class/corlib and run
generate-index.pl to create a very, very crude set of index files from
mscorlib.xml. Here's the output as of tonight:
http://www.rinspin.com/~bronson/mono/xsl-test-1/show-namespace.xsl--%5B%5D.html
This output is utter crap, of course! This is just to demonstrate the
mechanism.
I'm using links of the form:
<a href="show-namespace.xsl--mscorlib.xml[ns=System.IO].html">
System.IO
</a>
This says to run show-namespace.xsl on mscorlib.xml passing System.IO as
the "ns" parameter (this generates the index for the System.IO
namespace). The output can either be saved to disk and navigated using
a traditional web browser or dynamically re-generated on demand from the
information in the filename. Should be the best of both worlds.
School is going to be tough this week; I'm afraid I won't have much time
for hacking until Thursday afternoon...
--=-D6KG3KbByjBKQU8DxRPU
Content-Disposition: attachment; filename=generate-index.pl
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-perl; name=generate-index.pl; charset=ANSI_X3.4-1968
#!/usr/bin/perl -w
my $xml =3D 'mscorlib.xml';
open(FH, "xalan -Q -XSL list-namespaces.xsl -IN $xml |")
or die "Could not list namespaces: $!\n";
my @arr =3D <FH>;
close FH;
print "Generating (root)\n";
system("xalan -Q -XSL show-namespace.xsl -IN $xml -OUT show-namespace.xsl--=
[].html") =3D=3D 0 or die "Could not run xalan: returned $?\n";
for(@arr)
{
chomp;
print "Generating $_\n";
system("xalan -Q -XSL show-namespace.xsl -IN $xml -PARAM ns \"'$_'\" -OU=
T show-namespace.xsl--[$_].html") =3D=3D 0 or die "Could not run xalan: ret=
urned $?\n";
}
--=-D6KG3KbByjBKQU8DxRPU
Content-Disposition: attachment; filename=list-namespaces.xsl
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; name=list-namespaces.xsl; charset=ANSI_X3.4-1968
<!-- make-index.xsl Scott Bronson 13 Oct 2002 -->
<!-- This outputs a text list of the namespaces in the file, one per line. =
-->
<xsl:stylesheet xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform" version=
=3D"1.0">
<xsl:output method=3D"text"/>
<xsl:key name=3D'uniq' match=3D'class' use=3D'@namespace'/>
<xsl:template match=3D"/masterdoc">
<xsl:for-each select=3D"class[generate-id()=3Dgenerate-id(key('uniq',@nam=
espace)[1])]">
<xsl:sort select=3D"@namespace"/>
<xsl:value-of select=3D"@namespace"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
--=-D6KG3KbByjBKQU8DxRPU
Content-Disposition: attachment; filename=show-namespace.xsl
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; name=show-namespace.xsl; charset=ANSI_X3.4-1968
<!-- make-index.xsl Scott Bronson 11 Oct 2002 -->
<!-- This outputs an index of the given directory. -->
<xsl:stylesheet xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform" version=
=3D"1.0">
<xsl:output method=3D"html" encoding=3D"ISO-8859-1"/>
<!-- You MUST specify the namespace of the generated index on the
command line -->
<xsl:param name=3D"ns"/>
<xsl:key name=3D'uniq' match=3D'class' use=3D'@namespace'/>
<xsl:template match=3D"/masterdoc">
<html>
<head>
<title>
<xsl:call-template name=3D"print-namespace"/>
</title>
</head>
<body>
<h3> <center>
<xsl:call-template name=3D"print-namespace"/>
</center> </h3>
<table border=3D"1">
<tr><th>Subnamespaces</th></tr>
<tr><td>
<xsl:call-template name=3D"base-namespace">
<xsl:with-param name=3D"string" select=3D"$ns"/>
</xsl:call-template>
</td></tr>
<!-- sort and uniq the namespaces -->
<!-- it turns out it's really hard to make this hierarchical
if you don't have XSLT 2.0. Time to upgrade. -->
<xsl:for-each select=3D"class[generate-id()=3Dgenerate-id(key('uniq',@nam=
espace)[1])]">
<xsl:sort select=3D"@namespace"/>
<tr><td> <a href=3D"show-namespace.xsl--[{@namespace}].html">
<xsl:value-of select=3D"@namespace"/>
</a> </td></tr>
</xsl:for-each>
</table>
<p></p>
<table border=3D"1">
<tr><th>Class</th><th>Description</th></tr>
<xsl:choose>
<xsl:when test=3D"count(/masterdoc/class[@namespace=3D$ns])=3D0">
<tr><td colspan=3D"2"><i>No classes!</i></td></tr>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select=3D"/masterdoc/class[@namespace=3D$ns]">
<tr><td> <a href=3D"summary.xsl--{@name}.xml.html">
<xsl:value-of select=3D"@name"/>
</a> </td> <td>(unavailable)</td></tr>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</table>
</body>
</html>
</xsl:template>
<xsl:template name=3D"print-namespace">
<xsl:choose>
<xsl:when test=3D"string-length($ns)=3D0">
(root namespace)
</xsl:when>
<xsl:otherwise>
<xsl:value-of select=3D"$ns"/> namespace
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name=3D"base-namespace">
<xsl:param name=3D"string" />
<xsl:choose>
<xsl:when test=3D"string-length($string)=3D0">
<a href=3D"show-namespace.xsl--[].html">.. (parent)</a>
</xsl:when>
<xsl:when test=3D"substring($string,string-length($string))=3D'.'">
<a href=3D"{concat('show-namespace.xsl--[', substring($string,1,strin=
g-length($string)-1), '].html')}">.. (parent)</a>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name=3D"base-namespace">
<xsl:with-param name=3D"string" select=3D"substring($string,1,strin=
g-length($string)-1)"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- This is the opposite - it returns the filename
<xsl:template name=3D"end-namespace">
<xsl:param name=3D"string" />
<xsl:choose>
<xsl:when test=3D"contains($string, '.')">
<xsl:call-template name=3D"end-namespace">
<xsl:with-param name=3D"string" select=3D"substring-after($string,'=
.')" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select=3D"$string" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
-->
</xsl:stylesheet>
--=-D6KG3KbByjBKQU8DxRPU--