You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ja...@apache.org on 2002/05/07 08:06:11 UTC
cvs commit: xml-xerces/perl/docs readme.pl readme.xsl
jasons 02/05/06 23:06:10
Added: perl/docs readme.pl readme.xsl
Log:
XSLT files for creating README from readme.xml
Revision Changes Path
1.1 xml-xerces/perl/docs/readme.pl
Index: readme.pl
===================================================================
#!/usr/local/bin/perl5.7.2
# author: Jason E. Stewart (jason@openinformatics.com)
# Copyright 2002 Jason E. Stewart
#
use strict;
use Getopt::Long;
use File::Temp qw(tempfile);
use XML::Xalan;
use Text::Wrap;
my %OPTIONS;
# $OPTIONS{program} = 'xalan';
$OPTIONS{output} = '/home/jasons/work/xml-xerces/perl/README';
$OPTIONS{xslt} = '/home/jasons/work/xml-xerces/perl/docs/readme.xsl';
$OPTIONS{input} = '/home/jasons/build/apach-www-tools/xml-site/sources/xerces-p/readme.xml';
my $rc = GetOptions(\%OPTIONS,
'--output=s',
'--xslt=s',
'--input=s',
'--program=s',
'help');
my $USAGE = <<EOU;
usage: $0 [options]
options:
--input=file - name of input xml file
(defaults to $OPTIONS{input})
--output=file - name of output genex2 xml file
(defaults to $OPTIONS{output})
--program=file - name of xslt program
(defaults to $OPTIONS{program})
--xslt - name of xslt stylesheet to use
(defaults to $OPTIONS{xslt})
--help - this message
EOU
die $USAGE if exists $OPTIONS{help};
die $rc, $USAGE unless $rc;
my ($temp_fh,$temp_file) = tempfile('tempXXXX',UNLINK=>1);
my $DOCTYPE = "<!DOCTYPE s1 [\n";
open(IN,$OPTIONS{input})
or die "Couldn't open $OPTIONS{input} for reading";
# first we print out the XML_Decl and the new DOCTYPE
my $input;
$input = <IN>;
$input .= $DOCTYPE;
# then throw away the original DOCTYPE
$_ = <IN>;
while (<IN>) {
$input .= $_;
}
close(IN);
my $tr = XML::Xalan::Transformer->new();
my $namespace = "http://xml.apache.org/xalan-p/external_function";
my $func = sub {
my ($first_indent,$subsequent_indent,$text) = @_;
return wrap(' ' x $first_indent,
' ' x $subsequent_indent,
$text);
};
$tr->install_function($namespace, 'wrap', $func);
my $parsed = $tr->parse_string($input);
my $res = $tr->transform_to_file($parsed, # input
$OPTIONS{xslt}, # stylesheet
$OPTIONS{output}); # output
die "Error transforming: ", $tr->errstr
unless $res;
exit(0);
1.1 xml-xerces/perl/docs/readme.xsl
Index: readme.xsl
===================================================================
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE xsl:stylesheet>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:external="http://xml.apache.org/xalan-p/external_function"
exclude-result-prefixes="external"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:output method="text"/>
<!-- only purpose is so we can die early if wrap() isn't available -->
<xsl:template match="/">
<xsl:if test="not(function-available('external:wrap'))">
<xsl:message terminate="yes">
Function external:wrap() is not available!
</xsl:message>
</xsl:if>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="s1">
<xsl:text>============================================================</xsl:text>
<xsl:text> </xsl:text><!-- a newline -->
<xsl:value-of select="@title"/>
<xsl:text> </xsl:text><!-- a newline -->
<xsl:text>============================================================</xsl:text>
<xsl:text> </xsl:text><!-- a newline -->
<xsl:text> </xsl:text><!-- a newline -->
<xsl:text> $Id: readme.xsl,v 1.1 2002/05/07 06:06:10 jasons Exp $</xsl:text>
<xsl:text> </xsl:text><!-- a newline -->
<xsl:text>
LEGAL HOOP JUMPING:
===================
This code is distributed under the terms of the Apache Software
License, Version 1.1. See the file LICENSE for details</xsl:text>
<xsl:text> </xsl:text><!-- a newline -->
<xsl:text> </xsl:text><!-- a newline -->
<xsl:text> </xsl:text><!-- a newline -->
<xsl:text> </xsl:text><!-- a newline -->
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="s2">
<xsl:number format="1) "/>
<xsl:value-of select="@title"/>
<xsl:text> </xsl:text><!-- a newline -->
<xsl:text>========================</xsl:text>
<xsl:text> </xsl:text><!-- a newline -->
<xsl:text> </xsl:text><!-- a newline -->
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="s3">
<xsl:text> </xsl:text>
<xsl:number level="multiple" format="1.1) " count="s2|s3"/>
<xsl:value-of select="@title"/>
<xsl:text> </xsl:text><!-- a newline -->
<xsl:text> </xsl:text>
<xsl:text>------------------------</xsl:text>
<xsl:text> </xsl:text><!-- a newline -->
<xsl:text> </xsl:text><!-- a newline -->
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="note">
<xsl:variable name="text">
<xsl:apply-templates/>
</xsl:variable>
<xsl:text>	</xsl:text><!-- a tab -->
<xsl:text>#### NOTE: ####</xsl:text>
<xsl:text> </xsl:text><!-- a newline -->
<xsl:value-of select="external:wrap(8,8,normalize-space($text))"/>
<xsl:text> </xsl:text><!-- a newline -->
<xsl:text>	</xsl:text><!-- a tab -->
<xsl:text>###############</xsl:text>
<xsl:text> </xsl:text><!-- a newline -->
<xsl:text> </xsl:text><!-- a newline -->
</xsl:template>
<!-- we include the external URL after the text -->
<xsl:template match="jump">
<xsl:value-of select="."/>
<xsl:text> <URL: </xsl:text>
<xsl:value-of select="@href"/>
<xsl:text>> </xsl:text>
</xsl:template>
<xsl:template match="ul/li | ol/li">
<xsl:variable name="text">
<xsl:apply-templates/>
</xsl:variable>
<xsl:variable name="bullet">
<xsl:choose>
<xsl:when test="parent::ol">
<xsl:number format="A) "/>
</xsl:when>
<xsl:otherwise>
<xsl:text>* </xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="indent">
<xsl:choose>
<xsl:when test="ancestor::*[2][self::ol] or ancestor::*[2][self::ul]">
<xsl:number value="8"/>
</xsl:when>
<xsl:otherwise>
<xsl:number value="4"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- create the indent -->
<xsl:call-template name="x">
<xsl:with-param name="count" select="$indent"/>
<xsl:with-param name="string" select="string(' ')"/>
</xsl:call-template>
<xsl:value-of select="$bullet"/>
<xsl:value-of select="external:wrap(0,4+$indent,normalize-space($text))"/>
<xsl:text> </xsl:text><!-- a newline -->
</xsl:template>
<!-- only match paragraphs without anchors -->
<xsl:template match="p[not(anchor)]">
<xsl:variable name="text">
<xsl:apply-templates/>
</xsl:variable>
<xsl:variable name="first">
<xsl:choose>
<xsl:when test="parent::s2">
<xsl:number value="0"/>
</xsl:when>
<xsl:otherwise>
<xsl:number value="4"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="subsequent">
<xsl:choose>
<xsl:when test="parent::s2">
<xsl:number value="0"/>
</xsl:when>
<xsl:otherwise>
<xsl:number value="4"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="external:wrap($first,
$subsequent,
normalize-space($text))"/>
<xsl:text > </xsl:text><!-- a newline -->
<xsl:text > </xsl:text><!-- a newline -->
</xsl:template>
<xsl:template match="ul|ol">
<xsl:apply-templates/>
<xsl:text > </xsl:text><!-- a newline -->
</xsl:template>
<xsl:template match="source">
<xsl:apply-templates/>
<xsl:text > </xsl:text><!-- a newline -->
</xsl:template>
<xsl:template match="em">
<xsl:text>*</xsl:text>
<xsl:apply-templates/>
<xsl:text>*</xsl:text>
</xsl:template>
<!-- named after the Perl operator 'x' -->
<xsl:template name="x">
<xsl:param name="count"/>
<xsl:param name="string"/>
<xsl:choose>
<xsl:when test="$count > 0">
<xsl:variable name="rest">
<xsl:call-template name="x">
<xsl:with-param name="count" select="$count - 1"/>
<xsl:with-param name="string" select="$string"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="concat($string, $rest)"/>
</xsl:when>
<xsl:otherwise>
<xsl:text/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org