#!/usr/bin/perl

# This script creates an HTML documentation for loncapa.xsd

use XML::LibXSLT;
use XML::LibXML;
use Cwd 'abs_path';

my $script_dir = abs_path($0);
my ($current_dir) = $script_dir =~ /^(.*\/).*$/;
my $xsl_path = $current_dir . 'XMLSchema.xsl';
my $schema_path = $current_dir.'../graphical_editor/loncapa_daxe/web/config/loncapa.xsd';
my $html_path = $current_dir.'loncapa.html';

my $parser = XML::LibXML->new();
my $xslt = XML::LibXSLT->new();

my $source = $parser->parse_file($schema_path);
my $style_doc = $parser->parse_file('XMLSchema.xsl');

my $stylesheet = $xslt->parse_stylesheet($style_doc);

my %parameters = (
  'jaxe-uri-xsl' => "'".$xsl_path."'",
  'titre' => "'LON-CAPA language reference'",
  'langue' => "'en'",
);
my $result = $stylesheet->transform($source, %parameters);

print $stylesheet->output_file($result, $html_path);

print "loncapa.html has been updated.\n";

