#!/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. # * Generalise so that the LaTeX output is split to use a separate hyperlink for each word in the link label (to allow the links to be wrapped across lines). HTML version doesn't need to be changed. # I figure this is also a sensible place to store the root of the Oracle documentation on the department's Web server. # Should this have a trailing slash (appropriate for standalone URL) or not (appropriate for a prefix for composite URLs)? $oracle_documentation_root = "http://info-nts-12.otago.ac.nz/docs/oracle11gr1/"; # Here's the raw data. # Each entry has a name (marked up as XML), a unique, short, space-less code name for it, and the actual URL. # It's probably sensible to have the full URL here, rather than prefixing the Oracle document root, because it's easier to copy the entire URL from the Web browser when updating. @references = ( # Name(0) Code(1) URL(2) "Documentation Docs " . $oracle_documentation_root, "Database Administrator<apostrophe/>s Guide Admin http://info-nts-12.otago.ac.nz/docs/oracle11gr1/server.111/b28310/toc.htm", "2 Day Developer<apostrophe/>s Guide AppDev2Day http://info-nts-12.otago.ac.nz/docs/oracle11gr1/appdev.111/b28843/toc.htm", "Advanced Application Developer<apostrophe/>s Guide AppDevAdv http://info-nts-12.otago.ac.nz/docs/oracle11gr1/appdev.111/b28424/toc.htm", "Object-Relational Developer<apostrophe/>s Guide AppDevOR http://info-nts-12.otago.ac.nz/docs/oracle11gr1/appdev.111/b28371/toc.htm", "Database Concepts Concepts http://info-nts-12.otago.ac.nz/docs/oracle11gr1/server.111/b28318/toc.htm", "Data Warehousing Guide DataWarehousing http://info-nts-12.otago.ac.nz/docs/oracle11gr1/server.111/b28313/toc.htm", "Database Error Messages Errors http://info-nts-12.otago.ac.nz/docs/oracle11gr1/server.111/b28278/toc.htm", "SQL Reference SQL http://info-nts-12.otago.ac.nz/docs/oracle11gr1/server.111/b28286/toc.htm", "Java Developer<apostrophe/>s Guide Java http://info-nts-12.otago.ac.nz/docs/oracle11gr1/java.111/b31225/toc.htm", "JDBC Developer<apostrophe/>s Guide and Reference JDBC http://info-nts-12.otago.ac.nz/docs/oracle11gr1/java.111/b31224/toc.htm", "Database Master Glossary Glossary http://info-nts-12.otago.ac.nz/docs/oracle11gr1/mix.111/b14388/toc.htm", "Performance Tuning Guide Tuning http://info-nts-12.otago.ac.nz/docs/oracle11gr1/server.111/b28274/toc.htm", "PL/SQL User<apostrophe/>s Guide and Reference PLSQL http://info-nts-12.otago.ac.nz/docs/oracle11gr1/appdev.111/b28370/toc.htm", "Database Master Index Index http://info-nts-12.otago.ac.nz/docs/oracle11gr1/mix.111/b14387/toc.htm", "Database Reference Reference http://info-nts-12.otago.ac.nz/docs/oracle11gr1/server.111/b28320/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=\"http://www.w3.org/1999/XSL/Transform\">\n"; } # One-off hard-coded template for a link to the root of the documentation set, using the URL as the anchor text. # This is used in several places in the INFO 212 course book and updating them is more of a pain than implementing this! if ($output_type eq "xslt") { print "<xsl:template name=\"OraDocsURL\" match=\"OraDocsURL\"><xsl:call-template name=\"empty-hyperlink-url-internal\"><xsl:with-param name=\"url\">" . $oracle_documentation_root . "</xsl:with-param></xsl:call-template></xsl:template>\n"; # print "<xsl:template name=\"OraDocsURL\" match=\"OraDocsURL\"><xsl:apply-templates><xsl:element name=\"hyperlink\"><xsl:attribute name=\"url\">" . $oracle_documentation_root . "</xsl:attribute></xsl:element></xsl:apply-templates></xsl:template>\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:template name=\"" . $oracle_prefix . $_[1] . "\" match=\"" . $oracle_prefix . $_[1] . "\">" . "<xsl:call-template name=\"hyperlink-internal\">" . # mode=\"hyperlink-internal\">" . "<xsl:with-param name=\"url\">" . $_[2] . "</xsl:with-param>" . "<xsl:with-param name=\"label\">" . "<xsl:call-template name=\"OracleServer\"/>" . " " . $_[0] . "</xsl:with-param>" . "</xsl:call-template>" . "</xsl: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>"; }