Newer
Older
XML / oracle-docs.perl
#!/usr/bin/perl
#
# $Id$
# 
# Basic script for generating XML markup for the major sections of the Oracle Documentation, and XSLT templates (and meta-templates, for both output formats) for transforming it.
# 
# To do:
#  * Maybe modify the script to work for any URL-based hyperlinks (e.g. <Blackboard/>, <OtagoUniversity/>).  This would mean ditching the automatic "Ora" prefix, but wouldn't require much else to implement.
 

# Here's the raw data (this used to be in an Excel spreadsheet, which now obviously shouldn't be used any more - might remove from CVS some time).
# Each entry has a name (marked up as XML), a unique, short, space-less code name for it, and the actual URL.
@references =
(
	# Name(0)	Code(1)	URL(2)
	"Database Administrator<apostrophe/>s Guide					Admin		http://info-nts-12.otago.ac.nz/docs/oracle9i/server.920/a96521/toc.htm",
	"Application Developer<apostrophe/>s Guide<emdash/>Object-Relational Features	AppDevOR	http://info-nts-12.otago.ac.nz/docs/oracle9i/appdev.920/a96594/toc.htm",
	"Database Concepts								Concepts	http://info-nts-12.otago.ac.nz/docs/oracle9i/server.920/a96524/toc.htm",
	"Data Warehousing								DataWarehousing	http://info-nts-12.otago.ac.nz/docs/oracle9i/server.920/a96520/toc.htm",
	"Database Error Messages							Errors		http://info-nts-12.otago.ac.nz/docs/oracle9i/server.920/a96525/toc.htm",
	"SQL Reference									SQL		http://info-nts-12.otago.ac.nz/docs/oracle9i/server.920/a96540/toc.htm",
	"Java Developer<apostrophe/>s Guide						Java		http://info-nts-12.otago.ac.nz/docs/oracle9i/java.920/a96656/toc.htm",
	"JDBC Developer<apostrophe/>s Guide and Reference				JDBC		http://info-nts-12.otago.ac.nz/docs/oracle9i/java.920/a96654/toc.htm",
	"Database Master Glossary							Glossary	http://info-nts-12.otago.ac.nz/docs/oracle9i/mix.920/a97290/toc.htm",
	"Database Performance Tuning Guide and Reference				Tuning		http://info-nts-12.otago.ac.nz/docs/oracle9i/server.920/a96533/toc.htm",
	"PL/SQL User<apostrophe/>s Guide and Reference					PLSQL		http://info-nts-12.otago.ac.nz/docs/oracle9i/appdev.920/a96624/toc.htm",
	"Database Master Index								Index		http://info-nts-12.otago.ac.nz/docs/oracle9i/mix.920/a96625/toc.htm",
	"Database Reference								Reference	http://info-nts-12.otago.ac.nz/docs/oracle9i/server.920/a96536/toc.htm"
);

# Prefix to use in the generated template names:
$oracle_prefix = "Ora";

if ($#ARGV != 1)
{
	warn "usage: oracle-docs <section-code-regexp> (xml | xslt | xslt_html | xslt_latex | link | all)\n";
	exit;
}

$section_code = $ARGV[0];
$output_type = $ARGV[1];

if ($output_type eq "xslt") {
	print "<?xml version=\"1.0\"?>\n" . 
		"<!-- Do not edit!  Automatically generated by oracle-docs.perl! -->\n" . 
		"<stylesheet version=\"1.0\" xmlns:xsl-out=\"http://www.w3.org/1999/XSL/Transform\">\n";
}
	
foreach $current_record (@references) {
	@fields = split(/[	]+/, $current_record);
	# Only print the entries for the matching section:
	if (@fields[1] =~ /$section_code/) {
		# Print the requested stuff:
		if ($output_type eq "link") {
			print generate_doc_netlink(@fields[0], @fields[2]) . "\n";
		} elsif ($output_type eq "xml") {
			print generate_xml(@fields[1]) . "\n";
		} elsif ($output_type eq "xslt") {
			print generate_xsl_metatemplate(@fields[0], @fields[1], @fields[2]) . "\n";
		} elsif ($output_type eq "xslt_html") {
			print generate_xsl_template_for_html(@fields[0], @fields[1], @fields[2]) . "\n";
		} elsif ($output_type eq "xslt_latex") {
			print generate_xsl_template_for_latex(@fields[0], @fields[1], @fields[2]) . "\n";
		} elsif ($output_type eq "all") {
			print generate_doc_netlink(@fields[0], @fields[2]) . "\n";
			print generate_xsl_metatemplate(@fields[0], @fields[1], @fields[2]) . "\n";
			print generate_xsl_template_for_html(@fields[0], @fields[1], @fields[2]) . "\n";
			print generate_xsl_template_for_latex(@fields[0], @fields[1], @fields[2]) . "\n";
		} else {
			warn "Sorry - I don't know anything about a \"$output_type\" format.\n";
			exit;
		}
	}
}

if ($output_type eq "xslt") {
	print "</stylesheet>\n";
}



# what we really need to produce is a template that calls the hyperlink template when matched.  I think.
# Markup for a hyperlink (as defined in format-master.xml) looks like this:
# 
# 	<hyperlink url="http://wherever/">Some Web Site</hyperlink>
# 
# However, this will only match elements with a url attribute; we therefore need a new internal hyperlink that's parameterised.  Should be modal (but "call-templates" doesn't seem to like it when you give it a "mode" attribute).
# The derived xml2html.xsl and xml2latex.xsl files will need to call this hyperlink-internal template directly:
#
# 	<xsl:call-template name="hyperlink-internal" mode="hyperlink-internal">
#		<xsl:with-param name="url">http://wherever/</xsl:with-param>
#		<xsl:with-param name="label">Some Web Site</xsl:with-param>
#	</xsl:call-template>

# Generate an XSLT meta-template for generating either an HTML or a LaTeX producing template.
# Arguments: (<descriptive-label>, <entry-code>, <url>)
sub generate_xsl_metatemplate {
	return "<xsl-out:template name=\"" . $oracle_prefix . $_[1] . "\" match=\"" . $oracle_prefix . $_[1] . "\">" . 
		"<xsl-out:call-template name=\"hyperlink-internal\">" . # mode=\"hyperlink-internal\">" .
		"<xsl-out:with-param name=\"url\">" . $_[2] . "</xsl-out:with-param>" .
		"<xsl-out:with-param name=\"label\">" . "<xsl-out:call-template name=\"OracleServer\"/>" . " " . $_[0] . "</xsl-out:with-param>" .
		"</xsl-out:call-template>" .
		"</xsl-out:template>";
	
	# Nope, wrong tree here:
	return "<xsl:template name=\"" . $oracle_prefix . $_[1] . "\" match=\"" . $oracle_prefix . $_[1] . "\">" . 
		"<latex>" . "\\href{" . $_[2] . "}" . "{" . "<xsl:call-template name=\"OracleServer\"/>" . " " . $_[0] . "}" . "</latex>" . 
		"<html>" . "<a href=\"" . $_[2]. "\">" . "<xsl:call-template name=\"OracleServer\"/>" . " " . $_[0] . "</a>" . "</html>" . 
		"</xsl:template>";
}


# Produce the actual XML markup to be used in authoring (just to provide a handy list of them all):
# Arguments: (<entry-code>)
sub generate_xml {
	return "<" . $oracle_prefix . $_[0]. "/>";
}

# Produce XML markup for a link to a section of the documentation (deprecated):
sub generate_doc_netlink {
	return "<netlink><label>" . $_[0] . "</label><target>" . $_[1] . "</target></netlink>";
}

# Generate an XSLT template for HTML output (deprecated):
sub generate_xsl_template_for_html {
		return "<xsl:template match=\"" . $_[0] . "\"><A><xsl:attribute name=\"HREF\">" . $_[1] . "</xsl:attribute>" . "<xsl:call-template name=\"OracleServer\"/> " . $_[2] . "</A></xsl:template>";
}

# Generate an XSLT template for LaTeX output (deprecated):
sub generate_xsl_template_for_latex {
	return "<xsl:template match=\"" . $_[0] . "\">\\href{" . $_[1] . "}{<xsl:call-template name=\"OracleServer\"/> " . $_[2] . "}</xsl:template>";
}