|
From: <sh...@us...> - 2007-08-08 14:22:49
|
Revision: 45
http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=45&view=rev
Author: shaplov
Date: 2007-08-08 07:22:50 -0700 (Wed, 08 Aug 2007)
Log Message:
-----------
fb2_notes - is a script that allows to convert some XML comments into fb2 footnotes.
Added Paths:
-----------
trunk/fb2-perl-tools/fb2/Footnotes.pm
trunk/fb2-perl-tools/fb2_notes
Added: trunk/fb2-perl-tools/fb2/Footnotes.pm
===================================================================
--- trunk/fb2-perl-tools/fb2/Footnotes.pm (rev 0)
+++ trunk/fb2-perl-tools/fb2/Footnotes.pm 2007-08-08 14:22:50 UTC (rev 45)
@@ -0,0 +1,287 @@
+package fb2::Footnotes;
+
+our $VERSION=0.01;
+
+use strict;
+use XML::LibXML;
+
+=head1 NAME
+
+fb2::Footnotes - manipulates footnotes in fb2 e-book
+
+=head1 SYNOPSIS
+
+ use fb2::Footnotes;
+ use XML::LibXML;
+
+ my $parser = XML::LibXML->new();
+ my $doc = $parser->parse_file($ARGV[0]);
+
+ fb2::Footnotes::ConvertFromComments($doc,{Keyword => 'NOTE', UseNumber => 1});
+
+=head1 DESCRIPTION
+
+fb2::Footnotes provides a set of functions for manipulating footnotes in fb2 e-book.
+
+=head1 METHODS
+
+The following methods are provided in this module.
+
+=cut
+
+=head2 ConvertFromComments
+
+ fb2::Footnotes::ConvertFromComments($document,{Option1 => 'Value1', Option2 => 'Value2'});
+
+Converts specially formated comments to fb2 footnotes. Returns 1 if convertation were successful, and 0 if no changes were
+made.
+
+I<$document> - Fb2 e-book stored as an XML::LibXML Document object
+
+=over 4
+
+=item B<Options>
+
+I<Keyword> - All the comments that begins with the keyword will be converted into footnotes. The default value is 'NOTE';
+
+I<UseNumber> - If this option is true, B<ConvertFromComments> will take a number after Keyword as a number of footnote.
+Default value is 1;
+
+=back
+
+
+=cut
+
+sub ConvertFromComments
+{
+ my $doc = shift;
+ my $opt = shift || {};
+
+ $opt->{'Keyword'}='NOTE' unless $opt->{'Keyword'};
+ $opt->{'UseNumber'}=1 unless $opt->{'UseNumber'};
+
+ my $keyword = $opt->{'Keyword'};
+ my $use_number = $opt->{'UseNumber'};
+
+ my $root = $doc->getDocumentElement();
+ my $changes_flag = 0;
+
+
+ my @NodeList=();
+ foreach ('p','v','subtitle','th', 'td','text-author')
+ {
+ my @l = $doc->getElementsByTagName($_);
+
+ @NodeList=(@NodeList,@l);
+ }
+
+ foreach (@NodeList)
+ {
+ foreach ($_->childNodes)
+ {
+ if ($_->nodeType == XML_COMMENT_NODE)
+ {
+ my $node=$_;
+ if ( $node->data()=~/^\s*$keyword(.*)/ )
+ {
+ my $text=$1;
+ my $number = int(rand(10000));
+ if ($use_number && ($text=~/^(\d+)\s+(.*)$/) )
+ {
+ $text = $2;
+ $number = $1;
+ }
+ Add({'doc'=>$doc, 'Number' => $number, 'Text' => $text, 'InsertBefore' => $node });
+ $node->parentNode->removeChild($node);
+ $changes_flag = 1;
+ }
+ }
+ }
+ }
+ return($changes_flag);
+}
+
+=head2 Add
+
+ fb2::Footnotes::Add($document,{Option1 => 'Value1', Option2 => 'Value2'});
+
+ Adds a new footnote to a fb2 document.
+
+I<$document> - Fb2 e-book stored as an XML::LibXML Document object
+
+=over 4
+
+=item B<Options>
+
+I<Text> - Text of a new footnote
+
+I<Number> - Number of a new footnote
+
+I<InsertBefore> - XML::LibXML Node object. An <A href> link to a new footnote will be inserted
+before that node
+
+=back
+
+
+=cut
+
+sub Add
+{
+ my $opt = shift || {};
+
+ my $doc = $opt->{'doc'};
+ my $number = $opt->{'Number'};
+ my $text = $opt->{'Text'};
+ my $insert_before = $opt->{'InsertBefore'};
+
+
+ my $note_body=undef;
+
+ my ($book) = $doc->getElementsByTagName('FictionBook');
+ die "Cant find FictionBook element" unless $book;
+
+
+ foreach ($doc->getElementsByTagName('body'))
+ {
+ my $node = $_;
+ foreach ($node->attributes())
+ {
+ if ( ($_->nodeName eq 'type') && ($_->value eq 'note'))
+ {
+ # It's assumed that there is only one note-body in the book
+ $note_body = $node;
+ }
+ }
+ }
+ if (! $note_body)
+ {
+ $note_body = $doc->createElement('body');
+ $note_body->setAttribute('type','note');
+ $book->appendChild($doc->createTextNode(' '));
+ $book->appendChild($note_body);
+ $book->appendChild($doc->createTextNode("\n"));
+ }
+
+ my $section_node = $doc->createElement('section');
+ $section_node->setAttribute('id',"note$number");
+
+ # Create Title
+ my $p_node = $doc->createElement('p');
+ $p_node->appendChild($doc->createTextNode($number));
+ my $title_node = $doc->createElement('title');
+ $title_node->appendChild($p_node);
+
+ # Append Title
+ $section_node->appendChild($doc->createTextNode("\n "));
+ $section_node->appendChild($title_node);
+
+ # Create p
+ $p_node = $doc->createElement('p');
+ $p_node->appendChild($doc->createTextNode($text));
+
+ # Append p
+ $section_node->appendChild($doc->createTextNode("\n "));
+ $section_node->appendChild($p_node);
+ $section_node->appendChild($doc->createTextNode("\n "));
+
+
+ $note_body->appendChild($doc->createTextNode("\n "));
+ $note_body->appendChild($section_node);
+ $note_body->appendChild($doc->createTextNode("\n "));
+
+ ### Now will create <a href> tag and insert it...
+
+ my $xlink_namespace=undef;
+
+ foreach ($book->attributes())
+ {
+ # print $_->nodeName," ",$_->value,"\n";
+
+ if ($_->value=~/^http:\/\/www.w3.org\/1999\/xlink$/)
+ {
+ if ($_->nodeName=~/^.*\:(.*)$/)
+ {
+ $xlink_namespace=$1;
+ }
+ }
+ }
+
+# print "NameSpace = $xlink_namespace \n";
+
+ my $a_node = $doc->createElement('a');
+
+ if ($xlink_namespace)
+ {
+ $a_node->setAttribute("$xlink_namespace:href" ,"#note$number" );
+ } else
+ {
+ $a_node->setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href' ,"#note$number" );
+ }
+ $a_node->setAttribute('type','note');
+ $a_node->appendChild($doc->createTextNode("[$number]"));
+
+
+ $note_body->appendChild($a_node);
+ $insert_before->parentNode->insertBefore($a_node,$insert_before);
+
+
+# print $note_body->toString, "\n" if $note_body;
+}
+
+
+1;
+
+=head1 EXAMPLES
+
+=head2 ConvertFromComments
+
+ fb2::Footnotes::ConvertFromComments($doc, {Keyword => 'NOTE', UseNumber => 1});
+ fb2::Footnotes::ConvertFromComments($doc);
+
+Both will transform fb2 document from
+
+ <p>Some text here <!--NOTE112 Here is a text of a footnote--> Some more text</p>
+
+into
+
+ <p>Some text here <a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#note112" type="note">[112]</a>
+ Some more text</p>
+ ...
+ </body>
+ <body type="note">
+ <section id="note112">
+ <title><p>112</p></title>
+ <p>Here is a text of a footnote</p>
+ </section>
+ </body>
+
+
+=head2 Add
+
+ fb2::Footnotes::Add($doc,{Text => "Foot note text", Number => 4, InsertBefore => $some_node });
+
+=head1 SEE ALSO
+
+http://sourceforge.net/projects/fb2-perl-tools - fb2-perl-tools project page
+
+http://www.fictionbook.org/index.php/Eng:FictionBook - fb2 community (site is mostly in Russian)
+
+=head1 AUTHOR
+
+Nikolay Shaplov <N...@Sh...>
+
+=head1 VERSION
+
+0.01
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2007 by Nikolay Shaplov
+
+This library is free software; you can redistribute it and/or modify
+it under the terms of the General Public License (GPL). For
+more information, see http://www.fsf.org/licenses/gpl.txt
+
+=cut
+
+
Added: trunk/fb2-perl-tools/fb2_notes
===================================================================
--- trunk/fb2-perl-tools/fb2_notes (rev 0)
+++ trunk/fb2-perl-tools/fb2_notes 2007-08-08 14:22:50 UTC (rev 45)
@@ -0,0 +1,191 @@
+#!/usr/bin/perl
+
+use strict;
+use fb2::Footnotes;
+use XML::LibXML;
+use Encode;
+use Getopt::Long qw(HelpMessage VersionMessage);
+our $VERSION=0.01;
+
+=head1 NAME
+
+fb2_notes - manipulate footnotes in the fb2 e-book
+
+=head1 SYNOPSIS
+
+B<fb2_notes> B<convert> [B<-k>=I<keyword>] [B<-n>=[I<1>|I<0>]] I<filename.fb2>
+
+B<fb2_notes> B<convert> <I<src_file.fb2> >I<dst_file.fb2>
+
+=head1 DESCRIPTION
+
+This utility allows to convert specifically formated comments info fb2 footnotes
+
+=head1 COMMANDS
+
+=over 4
+
+=item B<convert>
+
+Converts XML comments that starts with B<keyword> into fb2 e-book footnotes. If B<use-number> is set to 1
+then number after B<keyword> will be used as a number of footnote. All other text of a comment will
+be saved as a text of the footnote
+
+=over 8
+
+=item B<-k> I<keyword_value>
+
+=item B<--keyword>=I<keyword_value>
+
+
+
+All XML comments that starts with I<keyword_value> will be
+converted into fb2 e-book footnotes. Default value is 'NOTE'.
+
+=item B<-n> [I<1>|I<0>]
+
+=item B<--use-number>=[I<1>|I<0>]
+
+If B<use-number> is set to 1, than a number after B<keyword> will be used as a number of footnote.
+Default value is 1.
+
+=back
+
+=back
+
+=head1 EXAMPLES
+
+=item B<convert>
+
+=over 4
+
+B<$ cat some_book.fb2>
+ ...
+ <p>Some text here<!--NOTE112 Here is a text of a footnote--> Some more text</p>
+ ...
+
+B<$ fb2_notes convert some_book.fb2>
+
+B<$ cat some_book.fb2>
+ ...
+ <p>Some text here<a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#note112" type="note">[112]</a>
+ Some more text</p>
+ ...
+ </body>
+ <body type="note">
+ <section id="note112">
+ <title><p>112</p></title>
+ <p>Here is a text of a footnote</p>
+ </section>
+ </body>
+
+=back
+
+=head1 SEE ALSO
+
+http://sourceforge.net/projects/fb2-perl-tools - fb2-perl-tools project page
+
+http://www.fictionbook.org/index.php/Eng:FictionBook - fb2 community (site is mostly in Russian)
+
+=head1 AUTHOR
+
+Nikolay Shaplov <N...@Sh...>
+
+=head1 VERSION
+
+0.01
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2007 by Nikolay Shaplov
+
+This library is free software; you can redistribute it and/or modify
+it under the terms of the General Public License (GPL). For
+more information, see http://www.fsf.org/licenses/gpl.txt
+
+=cut
+
+my $Command = shift @ARGV;
+
+do_convert() if $Command eq 'convert';
+HelpMessage() if ! $Command || $Command eq 'help';
+
+
+exit;
+
+
+sub do_convert
+{
+ my $opts={};
+ GetOptions(
+ help => sub {HelpMessage(); },
+ version => sub {VersionMessage(); },
+ "keyword|w=s" => \$opts->{'keyword'},
+ "use-number|n" => \$opts->{'use_number'},
+ );
+
+ my $file_name = $ARGV[0];
+
+ my $doc;
+
+ if ($file_name)
+ {
+ $doc = _parse_file($file_name);
+ } else
+ {
+ $doc = _parse_stdin();
+ }
+
+ my $changes_flag = fb2::Footnotes::ConvertFromComments($doc,{
+ "Keyword" => $opts->{'keyword'},
+ "UseNumber"=>$opts->{'use_number'}
+ });
+ if (! $changes_flag )
+ {
+ print STDERR "No changes were made\n";
+ return 0 unless $changes_flag;
+ }
+
+ if ($file_name)
+ {
+ _update_file($file_name,$doc);
+ } else
+ {
+ print $doc->toString();
+ }
+
+ print STDERR "Comments successfully converted\n";
+}
+
+sub _parse_file
+{
+ my $file_name=shift;
+ my $parser = XML::LibXML->new();
+
+ my $doc = $parser->parse_file($file_name);
+ return $doc;
+}
+
+sub _parse_stdin
+{
+ my $parser = XML::LibXML->new();
+ my $doc = $parser->parse_fh(\*STDIN);
+ return $doc;
+}
+
+sub _update_file
+{
+ my $file_name = shift;
+ my $doc = shift;
+
+ my $backup = $file_name . "~";
+ unlink $backup;
+ rename $file_name, $backup or die("Cannot make backup copy: $!");
+ my $encoding=$doc->encoding();
+ # This call of Encode::decode fixes problem in XML::DOM which do not
+ # mark entire output utf8 correctly.
+ my $data = decode("utf8",$doc->toString);
+ open DST,">:encoding($encoding)",$file_name;
+ print DST $data;
+ close DST;
+}
Property changes on: trunk/fb2-perl-tools/fb2_notes
___________________________________________________________________
Name: svn:executable
+ *
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sh...@us...> - 2007-08-08 14:34:42
|
Revision: 46
http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=46&view=rev
Author: shaplov
Date: 2007-08-08 07:34:35 -0700 (Wed, 08 Aug 2007)
Log Message:
-----------
An XSLT transformation fb2_to_docbook by KiR Jakobson
Someone should later write perl warp...
Added Paths:
-----------
trunk/fb2-perl-tools/xslt/
trunk/fb2-perl-tools/xslt/fb2docbook.xsl
trunk/fb2-perl-tools/xslt/fb2docbook_gen_infos.xsl
trunk/fb2-perl-tools/xslt/l10n/
trunk/fb2-perl-tools/xslt/l10n/en.xml
trunk/fb2-perl-tools/xslt/l10n/gentext.xsl
trunk/fb2-perl-tools/xslt/l10n/l10n.dtd
trunk/fb2-perl-tools/xslt/l10n/l10n.xml
trunk/fb2-perl-tools/xslt/l10n/ru.xml
trunk/fb2-perl-tools/xslt/params/
trunk/fb2-perl-tools/xslt/params/system_params.xsl
Added: trunk/fb2-perl-tools/xslt/fb2docbook.xsl
===================================================================
--- trunk/fb2-perl-tools/xslt/fb2docbook.xsl (rev 0)
+++ trunk/fb2-perl-tools/xslt/fb2docbook.xsl 2007-08-08 14:34:35 UTC (rev 46)
@@ -0,0 +1,800 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fb="http://www.gribuser.ru/xml/fictionbook/2.0"
+ xmlns:exsl="http://exslt.org/common" xmlns:redirect="http://xml.apache.org/xalan/redirect"
+ extension-element-prefixes="exsl redirect" exclude-result-prefixes="fb exsl redirect xlink"
+ version="1.1">
+ <xsl:import href="params/system_params.xsl"/>
+ <xsl:import href="l10n/gentext.xsl"/>
+ <xsl:import href="fb2docbook_gen_infos.xsl"/>
+ <xsl:param name="conv_info_idx"/>
+ <xsl:param name="document-element"/>
+ <xsl:output encoding="UTF-8" indent="yes" method="xml"
+ doctype-system="http://www.docbook.org/xml/4.4/docbookx.dtd"
+ doctype-public="-//OASIS//DTD DocBook XML V4.4//EN"/>
+ <xsl:key name="note-link" match="fb:section" use="@id"/>
+ <xsl:key name="binary-link" match="fb:binary" use="@id"/>
+ <xsl:template name="gen_binary_asciiname">
+ <xsl:param name="bin_href"/>
+ <xsl:value-of select="concat($bin_href, '.base64')"/>
+ </xsl:template>
+ <xsl:template name="gen_fname">
+ <xsl:param name="href"/>
+ <xsl:choose>
+ <xsl:when test="starts-with($href,'#')">
+ <xsl:value-of select="substring-after($href,'#')"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$href"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ <xsl:template name="get_docbook_format">
+ <xsl:param name="content-type"/>
+ <xsl:value-of
+ select="exsl:node-set($fb2.mime-types)/mime-type[@id=$content-type]/@docbook-format"/>
+ </xsl:template>
+ <xsl:template name="get_part_name">
+ <xsl:param name="level"/>
+ <xsl:variable name="num_levels" select="count(exsl:node-set($fb2.book-parts)/part)"/>
+ <xsl:choose>
+ <xsl:when test="$level > 0 and $level < $num_levels">
+ <xsl:value-of
+ select="exsl:node-set($fb2.book-parts)/part[@level=string($level)]/@name"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="exsl:node-set($fb2.book-parts)/part[last()]/@name"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ <xsl:template name="get_part_intro_name">
+ <xsl:param name="level"/>
+ <xsl:variable name="num_levels" select="count(exsl:node-set($fb2.book-parts)/part)"/>
+ <xsl:choose>
+ <xsl:when test="$level > 0 and $level < $num_levels">
+ <xsl:value-of
+ select="exsl:node-set($fb2.book-parts)/part[@level=string($level)]/@intro-name"
+ />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="exsl:node-set($fb2.book-parts)/part[last()]/@intro-name"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ <xsl:template match="fb:FictionBook">
+ <xsl:variable name="blang">
+ <xsl:choose>
+ <xsl:when test="fb:description/fb:title-info/fb:lang/text() != ''">
+ <xsl:value-of select="fb:description/fb:title-info/fb:lang/text()"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$fb2.default.language"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <book xml:lang="{$blang}">
+ <xsl:for-each select="fb:description">
+ <xsl:call-template name="bookinfo"/>
+ </xsl:for-each>
+ <xsl:apply-templates select="fb:body[not (@name = 'notes' or @name = 'footnotes')]"/>
+
+ <xsl:if test="$fb2.print.infos">
+ <xsl:call-template name="title-info-appendix"/>
+ <xsl:call-template name="src-title-info-appendix"/>
+ <xsl:call-template name="document-info-appendix"/>
+ <xsl:call-template name="publish-info-appendix"/>
+ <xsl:call-template name="custom-info-appendix"/>
+ <xsl:call-template name="technical-appendix"/>
+ </xsl:if>
+
+ <xsl:call-template name="binaries_index">
+ <xsl:with-param name="idx_fname">
+ <xsl:value-of select="$conv_info_idx"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ <xsl:apply-templates select="fb:binary"/>
+ <!--xsl:apply-templates select="fb:body[(@name = 'notes')]"/-->
+ </book>
+ </xsl:template>
+ <xsl:template name="bookinfo">
+ <bookinfo>
+ <xsl:if test="count(fb:title-info/fb:coverpage|fb:title-info/fb:annotation)">
+ <abstract id="preface_annotation" xml:lang="{fb:title-info/fb:lang/text()}">
+ <para>
+ <xsl:apply-templates select="fb:title-info/fb:coverpage/fb:image"/>
+ </para>
+ <xsl:for-each select="fb:title-info/fb:annotation/*">
+ <xsl:choose>
+ <xsl:when
+ test="local-name(.) = 'cite' or local-name(.) = 'empty-line' or local-name(.) = 'table'">
+ <para>
+ <xsl:apply-templates select="."/>
+ </para>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:apply-templates select="."/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ </abstract>
+ </xsl:if>
+ <xsl:if test="count(fb:src-title-info/fb:coverpage|fb:src-title-info/fb:annotation)">
+ <abstract id="preface_annotation_original"
+ xml:lang="{fb:src-title-info/fb:lang/text()}">
+ <para>
+ <xsl:apply-templates select="fb:src-title-info/fb:coverpage/fb:image"/>
+ </para>
+ <xsl:for-each select="fb:src-title-info/fb:annotation/*">
+ <xsl:choose>
+ <xsl:when
+ test="local-name(.) = 'cite' or local-name(.) = 'empty-line' or local-name(.) = 'table'">
+ <para>
+ <xsl:apply-templates select="."/>
+ </para>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:apply-templates select="."/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ <!--xsl:apply-templates select="fb:src-title-info/fb:annotation/*"/-->
+ </abstract>
+ </xsl:if>
+ <title>
+ <xsl:value-of select="fb:title-info/fb:book-title"/>
+ </title>
+ <xsl:choose>
+ <xsl:when test="count(fb:title-info/fb:author) > 1">
+ <authorgroup>
+ <xsl:apply-templates select="fb:title-info/fb:author" mode="bookinfo"/>
+ </authorgroup>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:apply-templates select="fb:title-info/fb:author" mode="bookinfo"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:apply-templates select="fb:title-info/fb:translator" mode="bookinfo"/>
+ <xsl:call-template name="bookinfo-sequence"/>
+ <xsl:call-template name="bookinfo-date"/>
+ <xsl:call-template name="bookinfo-publish"/>
+ </bookinfo>
+ </xsl:template>
+ <xsl:template name="bookinfo-publish">
+ <xsl:if test="count(fb:publish-info/fb:publisher)">
+ <publishername>
+ <xsl:value-of select="fb:publish-info/fb:publisher/text()"/>
+ </publishername>
+ </xsl:if>
+ <xsl:if test="count(fb:publish-info/fb:isbn)">
+ <bibliosource class="isbn">
+ <xsl:value-of select="fb:publish-info/fb:isbn/text()"/>
+ </bibliosource>
+ </xsl:if>
+ <xsl:if test="count(fb:publish-info/fb:year)">
+ <pubdate>
+ <xsl:value-of select="fb:publish-info/fb:year/text()"/>
+ </pubdate>
+ </xsl:if>
+ </xsl:template>
+ <xsl:template name="bookinfo-date">
+ <date>
+ <xsl:choose>
+ <xsl:when test="fb:title-info/fb:date/text() = ''">
+ <xsl:value-of select="fb:title-info/fb:date/@value"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="fb:title-info/fb:date/text()"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </date>
+ </xsl:template>
+ <xsl:template name="bookinfo-sequence">
+ <xsl:if test="count(fb:title-info/fb:sequence)">
+ <seriesvolnums>
+ <xsl:value-of select="fb:title-info/fb:sequence/@name"/>
+ </seriesvolnums>
+ <volumenum>
+ <xsl:value-of select="fb:title-info/fb:sequence/@number"/>
+ </volumenum>
+ </xsl:if>
+ </xsl:template>
+ <xsl:template match="fb:body">
+ <xsl:apply-templates select="@xml:lang|@id"/>
+ <xsl:if test="count(fb:image) or count(fb:epigraph)">
+ <preface id="{concat('preface_preface', generate-id())}">
+ <title id="{concat('prefacetitle', generate-id())}">
+ <xsl:call-template name="gentext.param">
+ <xsl:with-param name="param" select="'Preface'"/>
+ </xsl:call-template>
+ </title>
+ <xsl:apply-templates select="fb:image"/>
+ <xsl:apply-templates select="fb:epigraph"/>
+ </preface>
+ </xsl:if>
+ <xsl:for-each select="fb:section">
+ <xsl:call-template name="fb-section">
+ <xsl:with-param name="level" select="1"/>
+ </xsl:call-template>
+ </xsl:for-each>
+ </xsl:template>
+ <xsl:template name="fb-section">
+ <xsl:param name="level"/>
+ <xsl:variable name="part-name">
+ <xsl:call-template name="get_part_name">
+ <xsl:with-param name="level" select="$level"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:variable name="part-intro-name">
+ <xsl:call-template name="get_part_intro_name">
+ <xsl:with-param name="level" select="$level"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:element name="{$part-name}">
+ <xsl:apply-templates select="@xml:lang|@id"/>
+ <xsl:call-template name="section_title"/>
+ <xsl:choose>
+ <!-- если нет section в part, не загонять все в partintro; пустой partintro !!! -->
+ <xsl:when test="$part-intro-name != ''">
+ <xsl:element name="{$part-intro-name}">
+ <xsl:apply-templates
+ select="*[local-name(.) != 'section' and local-name(.) != 'title']"/>
+ </xsl:element>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:apply-templates
+ select="*[local-name(.) != 'section' and local-name(.) != 'title']"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:for-each select="fb:section">
+ <xsl:call-template name="fb-section">
+ <xsl:with-param name="level" select="$level + 1"/>
+ </xsl:call-template>
+ </xsl:for-each>
+ </xsl:element>
+ </xsl:template>
+ <xsl:template name="section_title">
+ <xsl:param name="role" select="''"/>
+ <title>
+ <xsl:if test="$role != ''">
+ <xsl:attribute name="role">
+ <xsl:value-of select="$role"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:for-each select="fb:title/fb:p">
+ <xsl:apply-templates/>
+ <xsl:text xml:space="preserve"> </xsl:text>
+ </xsl:for-each>
+ </title>
+ </xsl:template>
+ <xsl:template match="fb:p">
+ <para>
+ <xsl:if test="local-name(..) = 'section'">
+ <xsl:attribute name="role">p</xsl:attribute>
+ </xsl:if>
+ <xsl:apply-templates select="@xml:lang|@id"/>
+ <xsl:apply-templates/>
+ </para>
+ </xsl:template>
+ <xsl:template match="fb:p" mode="epigraph">
+ <para role="epigraph">
+ <xsl:apply-templates select="@xml:lang|@id"/>
+ <xsl:apply-templates/>
+ </para>
+ </xsl:template>
+ <!--xsl:template match="fb:epigraph">
+ <xsl:element name="epigraph">
+ <xsl:apply-templates select="@xml:lang|@id"/>
+ <xsl:if test="count(fb:text-author) != 0">
+ <attribution>
+ <xsl:apply-templates select="fb:text-author"/>
+ </attribution>
+ </xsl:if>
+ <xsl:apply-templates select="fb:p|fb:poem|fb:cite|fb:empty-line" mode="epigraph"/>
+ </xsl:element>
+ </xsl:template-->
+ <xsl:template match="fb:epigraph">
+ <xsl:element name="blockquote">
+ <xsl:apply-templates select="@xml:lang|@id"/>
+ <xsl:if test="count(fb:text-author) != 0">
+ <attribution>
+ <xsl:apply-templates select="fb:text-author"/>
+ </attribution>
+ </xsl:if>
+ <xsl:apply-templates select="*[local-name(.) != 'text-author']"/>
+ </xsl:element>
+ </xsl:template>
+ <xsl:template match="fb:empty-line" name="empty-line">
+ <literallayout/>
+ </xsl:template>
+ <xsl:template match="fb:empty-line" mode="epigraph">
+ <xsl:call-template name="empty-line"/>
+ </xsl:template>
+ <xsl:template match="fb:a">
+ <xsl:variable name="href_id">
+ <xsl:call-template name="gen_fname">
+ <xsl:with-param name="href" select="@xlink:href"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:choose>
+ <xsl:when test="@type = 'note'">
+ <xsl:call-template name="a_footnote">
+ <xsl:with-param name="href_id" select="$href_id"/>
+ <xsl:with-param name="label" select="text()"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="starts-with($href_id,'#')">
+ <xsl:call-template name="a_xref">
+ <xsl:with-param name="href_id" select="$href_id"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="a_ulink">
+ <xsl:with-param name="href_id" select="$href_id"/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ <xsl:template name="a_footnote">
+ <xsl:param name="href_id"/>
+ <xsl:param name="label"/>
+ <xsl:element name="footnote">
+ <xsl:attribute name="id">
+ <xsl:value-of select="$href_id"/>
+ </xsl:attribute>
+ <xsl:for-each select="key('note-link', $href_id)">
+ <!-- == work for XEP, in FOP only work labels without spaces == -->
+ <!--xsl:attribute name="label">
+ <xsl:choose>
+ <xsl:when test="$label = ''">
+ <xsl:value-of select="fb:title/fb:p/text()"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$label"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:attribute-->
+ <xsl:apply-templates select="fb:p"/>
+ </xsl:for-each>
+ <xsl:if test="count(key('note-link', $href_id)) = 0">
+ <xsl:message> Footnote body not found <xsl:value-of select="$href_id"/>!</xsl:message>
+ <para>
+ <xsl:call-template name="gentext.param">
+ <xsl:with-param name="param" select="'error.bad.note'"/>
+ </xsl:call-template>
+ <xsl:value-of select="$href_id"/>
+ <xsl:text>!</xsl:text>
+ </para>
+ </xsl:if>
+ </xsl:element>
+ </xsl:template>
+ <xsl:template name="a_ulink">
+ <xsl:param name="href_id"/>
+ <ulink url="{$href_id}">
+ <xsl:if test="@xlink:type != ''">
+ <xsl:attribute name="xlink:type">
+ <xsl:value-of select="@xlink:type"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:apply-templates/>
+ </ulink>
+ </xsl:template>
+ <xsl:template name="a_xref">
+ <xsl:param name="href_id"/>
+ <xref linkend="{$href_id}"/>
+ </xsl:template>
+ <xsl:template name="metadata_author">
+ <xsl:choose>
+ <xsl:when test="count(fb:nickname) and count(fb:first-name) = 0">
+ <xsl:value-of select="fb:nickname"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="fb:first-name"/>
+ <xsl:if test="count(fb:middle-name)">
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="fb:middle-name"/>
+ </xsl:if>
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="fb:last-name"/>
+ <xsl:if test="count(fb:nickname)">
+ <xsl:text> "</xsl:text>
+ <xsl:value-of select="fb:nickname"/>
+ <xsl:text>"</xsl:text>
+ </xsl:if>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ <xsl:template name="write_binaries_tree">
+ <conversion_info>
+ <page>
+ <dpi>
+ <width><xsl:value-of select="$output.dpi.width"/></width>
+ <height><xsl:value-of select="$output.dpi.height"/></height>
+ </dpi>
+ <size>
+ <width><xsl:value-of select="$page.width"/></width>
+ <height><xsl:value-of select="$page.height"/></height>
+ </size>
+ <max_image_margin>
+ <width><xsl:value-of select="$output.max_image_margin.width"/></width>
+ <height><xsl:value-of select="$output.max_image_margin.height"/></height>
+ </max_image_margin>
+ <images_mode>
+ <resize><xsl:value-of select="$output.images_mode.resize"/></resize>
+ <mode><xsl:value-of select="$output.images_mode.mode"/></mode>
+ </images_mode>
+ </page>
+ <metadata>
+ <Title>
+ <xsl:value-of select="/fb:FictionBook/fb:description/fb:title-info/fb:book-title"/>
+ </Title>
+ <Author>
+ <xsl:for-each select="/fb:FictionBook/fb:description/fb:title-info/fb:author[position() = 1]">
+ <xsl:call-template name="metadata_author"/>
+ </xsl:for-each>
+ <xsl:for-each select="/fb:FictionBook/fb:description/fb:title-info/fb:author[position() > 1]">
+ <xsl:text>; </xsl:text>
+ <xsl:call-template name="metadata_author"/>
+ </xsl:for-each>
+ </Author>
+ </metadata>
+ <binaries>
+ <xsl:for-each select="fb:binary">
+ <xsl:variable name="bin_ascii_name">
+ <xsl:call-template name="gen_binary_asciiname">
+ <xsl:with-param name="bin_href" select="@id"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <binary href_binary="{@id}" href_ascii="{$bin_ascii_name}"
+ content-type="{@content-type}"/>
+ </xsl:for-each>
+ </binaries>
+ </conversion_info>
+ </xsl:template>
+ <xsl:template name="binaries_index">
+ <xsl:param name="idx_fname"/>
+ <xsl:choose>
+ <xsl:when test="$document-element = 'exsl:document'">
+ <exsl:document href="{$idx_fname}" method="xml" encoding="UTF-8">
+ <xsl:call-template name="write_binaries_tree"/>
+ </exsl:document>
+ </xsl:when>
+ <xsl:when test="$document-element = 'xsl:document'">
+ <xsl:document href="{$idx_fname}" method="xml" encoding="UTF-8">
+ <xsl:call-template name="write_binaries_tree"/>
+ </xsl:document>
+ </xsl:when>
+ <xsl:when test="$document-element = 'redirect:write'">
+ <redirect:write file="{$idx_fname}">
+ <xsl:call-template name="write_binaries_tree"/>
+ </redirect:write>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:message> Unknown xsl:document element!!! </xsl:message>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ <xsl:template match="fb:binary">
+ <xsl:variable name="bin_ascii_name">
+ <xsl:call-template name="gen_binary_asciiname">
+ <xsl:with-param name="bin_href" select="@id"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:choose>
+ <xsl:when test="$document-element = 'exsl:document'">
+ <exsl:document href="{$bin_ascii_name}" method="text" indent="no">
+ <xsl:value-of select="text()"/>
+ </exsl:document>
+ </xsl:when>
+ <xsl:when test="$document-element = 'xsl:document'">
+ <xsl:document href="{$bin_ascii_name}" method="text" indent="no">
+ <xsl:value-of select="text()"/>
+ </xsl:document>
+ </xsl:when>
+ <xsl:when test="$document-element = 'redirect:write'">
+ <redirect:write file="{$bin_ascii_name}">
+ <xsl:value-of select="text()"/>
+ </redirect:write>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:message> Unknown xsl:document element!!! </xsl:message>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ <xsl:template match="fb:image">
+ <xsl:variable name="href_id">
+ <xsl:call-template name="gen_fname">
+ <xsl:with-param name="href" select="@xlink:href"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:variable name="content-type" select="key('binary-link', $href_id)/@content-type"/>
+ <xsl:variable name="docbook-format">
+ <xsl:call-template name="get_docbook_format">
+ <xsl:with-param name="content-type" select="$content-type"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:variable name="media_element">
+ <xsl:choose>
+ <xsl:when
+ test="local-name(..) = 'section' or local-name(..) = 'body' or local-name(..) = 'coverpage'"
+ >mediaobject</xsl:when>
+ <xsl:otherwise>inlinemediaobject</xsl:otherwise>
+ </xsl:choose>
+
+ </xsl:variable>
+ <xsl:element name="{$media_element}">
+ <xsl:apply-templates select="@xml:lang|@id"/>
+ <imageobject>
+ <imagedata align="{$fb2.image.align}" valign="{$fb2.image.valign}"
+ fileref="{$href_id}" format="{$docbook-format}"/>
+ </imageobject>
+ <xsl:if test="@alt != ''">
+ <textobject>
+ <xsl:value-of select="@alt"/>
+ </textobject>
+ </xsl:if>
+ <xsl:if test="@title != ''">
+ <caption>
+ <para>
+ <xsl:value-of select="@title"/>
+ </para>
+ </caption>
+ </xsl:if>
+ </xsl:element>
+ </xsl:template>
+ <xsl:template match="fb:emphasis">
+ <emphasis>
+ <xsl:apply-templates/>
+ </emphasis>
+ </xsl:template>
+ <xsl:template match="fb:strong">
+ <emphasis role="strong">
+ <xsl:apply-templates/>
+ </emphasis>
+ </xsl:template>
+ <xsl:template match="fb:strikethrough">
+ <emphasis role="strikethrough">
+ <xsl:apply-templates/>
+ </emphasis>
+ </xsl:template>
+ <xsl:template match="fb:sub">
+ <subscript>
+ <xsl:apply-templates/>
+ </subscript>
+ </xsl:template>
+ <xsl:template match="fb:sup">
+ <superscript>
+ <xsl:apply-templates/>
+ </superscript>
+ </xsl:template>
+ <xsl:template match="fb:code">
+ <code>
+ <xsl:apply-templates select="@xml:lang|@id"/>
+ <xsl:apply-templates/>
+ </code>
+ </xsl:template>
+ <xsl:template match="fb:cite" name="cite">
+ <blockquote>
+ <xsl:apply-templates select="@xml:lang|@id"/>
+ <xsl:if test="count(fb:text-author) != 0">
+ <attribution>
+ <xsl:apply-templates select="fb:text-author"/>
+ </attribution>
+ </xsl:if>
+ <xsl:apply-templates select="*[local-name(.) != 'text-author']"/>
+ </blockquote>
+ </xsl:template>
+ <xsl:template match="fb:cite" mode="epigraph">
+ <xsl:call-template name="cite"/>
+ </xsl:template>
+ <xsl:template match="fb:text-author">
+ <author>
+ <personname>
+ <othername>
+ <xsl:value-of select="text()"/>
+ </othername>
+ </personname>
+ </author>
+ </xsl:template>
+ <xsl:template match="fb:poem" mode="epigraph">
+ <xsl:call-template name="poem"/>
+ </xsl:template>
+ <xsl:template match="fb:poem" name="poem">
+ <xsl:choose>
+ <xsl:when test="count(fb:title) > 0">
+ <formalpara role="poem">
+ <xsl:apply-templates select="@xml:lang|@id"/>
+ <xsl:call-template name="section_title">
+ <xsl:with-param name="role" select="'poem'"/>
+ </xsl:call-template>
+ <xsl:apply-templates select="fb:epigraph"/>
+ <para role="poem">
+ <xsl:apply-templates select="fb:stanza"/>
+ <xsl:apply-templates select="fb:text-author"/>
+ <xsl:apply-templates select="fb:date"/>
+ </para>
+ </formalpara>
+ </xsl:when>
+ <xsl:otherwise>
+ <para role="poem">
+ <xsl:apply-templates select="@xml:lang|@id"/>
+ <xsl:apply-templates select="fb:epigraph"/>
+ <xsl:apply-templates select="fb:stanza"/>
+ <xsl:apply-templates select="fb:text-author"/>
+ <xsl:apply-templates select="fb:date"/>
+ </para>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ <xsl:template match="fb:stanza">
+ <xsl:choose>
+ <xsl:when test="count(fb:title) > 0">
+ <formalpara role="poem">
+ <xsl:call-template name="section_title"/>
+ <para role="poem">
+ <xsl:apply-templates select="@xml:lang|@id"/>
+ <literallayout xml:space="preserve" role="poem">
+ <xsl:apply-templates select="fb:v"/>
+ </literallayout>
+ </para>
+ </formalpara>
+ </xsl:when>
+ <xsl:otherwise>
+ <literallayout xml:space="preserve" role="poem"><xsl:apply-templates select="@xml:lang|@id"/><xsl:apply-templates select="fb:v"/></literallayout>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ <xsl:template match="fb:v">
+ <xsl:choose>
+ <xsl:when test="local-name(..) = 'stanza'">
+ <xsl:apply-templates/>
+ <xsl:text xml:space="preserve">
</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:message>
+ <xsl:text>Bad parent of tag v (must be stanza)!!!</xsl:text>
...
[truncated message content] |
|
From: <sh...@us...> - 2007-08-09 20:20:31
|
Revision: 48
http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=48&view=rev
Author: shaplov
Date: 2007-08-09 13:20:29 -0700 (Thu, 09 Aug 2007)
Log Message:
-----------
Move from XML::DOM to XML::LibXML, and some more fixes...
Modified Paths:
--------------
trunk/fb2-perl-tools/fb2/Description/Extend.pm
Added Paths:
-----------
trunk/fb2-perl-tools/fb2_descr
Removed Paths:
-------------
trunk/fb2-perl-tools/fb2_descr_extend.pl
Modified: trunk/fb2-perl-tools/fb2/Description/Extend.pm
===================================================================
--- trunk/fb2-perl-tools/fb2/Description/Extend.pm 2007-08-08 14:51:24 UTC (rev 47)
+++ trunk/fb2-perl-tools/fb2/Description/Extend.pm 2007-08-09 20:20:29 UTC (rev 48)
@@ -1,7 +1,9 @@
package fb2::Description::Extend;
use strict;
-use XML::DOM;
+use XML::LibXML;
+use XML::LibXML::Common;
+our $VERSION=0.02;
=head2 extend
@@ -110,7 +112,7 @@
my $par=shift;
my $node=shift;
- my $name=$node->getNodeName();
+ my $name=$node->nodeName();
my $doc=$node->getOwnerDocument;
my $children_info=_get_node_children_info($name);
@@ -126,11 +128,11 @@
foreach my $child ($node->getChildNodes) # Loops all child nodes
{
- if ($child->getNodeType == ELEMENT_NODE) # When element node is found
+ if ($child->nodeType == ELEMENT_NODE()) # When element node is found
{
- my $num = $name_to_num{$child->getNodeName}; # Get it's number in children_info array
- die "Node '".$child->getNodeName."' is not allowed inside '".$node->getNodeName."'" unless defined $num;
- die "Invalid child node order inside '".$node->getNodeName."'" if $num<$last_processed_child_num;
+ my $num = $name_to_num{$child->nodeName}; # Get it's number in children_info array
+ die "Node '".$child->nodeName."' is not allowed inside '".$node->nodeName."'" unless defined $num;
+ die "Invalid child node order inside '".$node->nodeName."'" if $num<$last_processed_child_num;
for(my $i=$last_processed_child_num+1;$i<$num;$i++) # If there shuld be children between
{ # current child and last processed
@@ -175,13 +177,13 @@
}
}
- if ($node->getFirstChild && $node->getFirstChild->getNodeType == ELEMENT_NODE) # If first node is element_node
+ if ($node->getFirstChild && $node->getFirstChild->nodeType == ELEMENT_NODE) # If first node is element_node
{ # then add an offset, for better view
my $offset_node = $doc->createTextNode("\n".(' ' x $par->{'offset'}));
$node->insertBefore($offset_node,$node->getFirstChild);
}
- if ($node->getLastChild && $node->getLastChild->getNodeType == ELEMENT_NODE) # If last node is element_node
+ if ($node->getLastChild && $node->getLastChild->nodeType == ELEMENT_NODE) # If last node is element_node
{ # then add an offset, for better view
my $offset_node = $doc->createTextNode("\n".(' ' x ($par->{'offset'} - $par->{'offset_step'})));
$node->appendChild($offset_node);
Copied: trunk/fb2-perl-tools/fb2_descr (from rev 47, trunk/fb2-perl-tools/fb2_descr_extend.pl)
===================================================================
--- trunk/fb2-perl-tools/fb2_descr (rev 0)
+++ trunk/fb2-perl-tools/fb2_descr 2007-08-09 20:20:29 UTC (rev 48)
@@ -0,0 +1,103 @@
+#!/usr/bin/perl
+
+use fb2::Description::Extend;
+use XML::LibXML;
+use Encode;
+use Getopt::Long qw(HelpMessage VersionMessage);
+
+use strict;
+our $VERSION=0.02;
+
+=head1 NAME
+
+fb2_descr - extend description of fb2 file with all possible elements
+
+=head1 SYNOPSIS
+
+B<fb2_descr.pl> extend I<filename.fb2>
+
+=cut
+
+
+my $Command = shift @ARGV;
+
+do_extend() if $Command eq 'extend';
+HelpMessage() if ! $Command || $Command eq 'help';
+
+exit;
+
+
+
+sub do_extend
+{
+ my $opts={};
+ GetOptions(
+ help => sub {HelpMessage(); },
+ version => sub {VersionMessage(); },
+# "keyword|w=s" => \$opts->{'keyword'},
+# "use-number|n" => \$opts->{'use_number'},
+ );
+ my $file_name = $ARGV[0];
+ my $doc;
+
+ if ($file_name)
+ {
+ $doc = _parse_file($file_name);
+ } else
+ {
+ $doc = _parse_stdin();
+ }
+
+ my ($desc) = $doc->getElementsByTagName("description",0);
+ fb2::Description::Extend::extend({'description'=>$desc});
+
+# if (! $changes_flag )
+# {
+# print STDERR "No changes were made\n";
+# return 0 unless $changes_flag;
+# }
+
+ if ($file_name)
+ {
+ _update_file($file_name,$doc);
+ } else
+ {
+ print $doc->toString();
+ }
+
+ print STDERR "Description successfully extended\n";
+
+}
+
+sub _parse_file
+{
+ my $file_name=shift;
+ my $parser = XML::LibXML->new();
+
+ my $doc = $parser->parse_file($file_name);
+ return $doc;
+}
+
+sub _parse_stdin
+{
+ my $parser = XML::LibXML->new();
+ my $doc = $parser->parse_fh(\*STDIN);
+ return $doc;
+}
+
+sub _update_file
+{
+ my $file_name = shift;
+ my $doc = shift;
+
+ my $backup = $file_name . "~";
+ unlink $backup;
+ rename $file_name, $backup or die("Cannot make backup copy: $!");
+ my $encoding=$doc->encoding();
+ # This call of Encode::decode fixes problem in XML::DOM which do not
+ # mark entire output utf8 correctly.
+ my $data = decode("utf8",$doc->toString);
+ open DST,">:encoding($encoding)",$file_name;
+ print DST $data;
+ close DST;
+}
\ No newline at end of file
Deleted: trunk/fb2-perl-tools/fb2_descr_extend.pl
===================================================================
--- trunk/fb2-perl-tools/fb2_descr_extend.pl 2007-08-08 14:51:24 UTC (rev 47)
+++ trunk/fb2-perl-tools/fb2_descr_extend.pl 2007-08-09 20:20:29 UTC (rev 48)
@@ -1,44 +0,0 @@
-#!/usr/bin/perl
-
-use fb2::Description::Extend;
-use XML::DOM;
-use Encode;
-use strict;
-our $VERSION=0.01;
-
-=head1 NAME
-
-fb2_descr_extend.pl - extend description of fb2 file with all possible elements
-
-=head1 SYNOPSIS
-
-B<fix_descr.pl> I<filename.fb2>
-
-=cut
-
-my $file_name = $ARGV[0];
-
-my $parser = new XML::DOM::Parser;
-
-my $doc = $parser->parsefile($file_name);
-my $root = $doc->getDocumentElement();
-
-
-my ($desc) = $root->getElementsByTagName("description",0);
-
-fb2::Description::Extend::extend({'description'=>$desc});
-
-
-my $backup = $file_name . "~";
-unlink $backup;
-rename $file_name, $backup or warn("Cannot make backup copy: $!");
-my $encoding=$doc->getXMLDecl()->getEncoding();
-
-# This call of Encode::decode fixes problem in XML::DOM which do not
-# mark entire output utf8 correctly.
-my $data = decode("utf8",$doc->toString);
-open DST,">:encoding($encoding)",$file_name;
-print DST $data;
-close DST;
-
-print "All OK\n";
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sh...@us...> - 2007-09-04 12:11:10
|
Revision: 51
http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=51&view=rev
Author: shaplov
Date: 2007-09-04 05:11:02 -0700 (Tue, 04 Sep 2007)
Log Message:
-----------
Now remove communiware dependences...
Modified Paths:
--------------
trunk/fb2-perl-tools/RTF/Control.pm
trunk/fb2-perl-tools/RTF/HTML/ansi
trunk/fb2-perl-tools/rtf2html
Modified: trunk/fb2-perl-tools/RTF/Control.pm
===================================================================
--- trunk/fb2-perl-tools/RTF/Control.pm 2007-09-04 12:09:14 UTC (rev 50)
+++ trunk/fb2-perl-tools/RTF/Control.pm 2007-09-04 12:11:02 UTC (rev 51)
@@ -56,12 +56,10 @@
process_char_props
reset_char_props
- set_input_charset
- set_output_charset
- $InMapper
- $OutMapper
from_unicode
- );
+ );
+
+
###########################################################################
%do_on_event = (); # output routines
@@ -107,14 +105,14 @@
die "Bad params for accept options" unless ref($optdef) eq 'HASH';
my %opts = %$optdef;
- # \xF0\xD2\xCF\xD7\xC5\xD2\xD1\xC5\xCD \xD7\xD3\xC5 \xD0\xC5\xD2\xC5\xC4\xC1\xCE\xCE\xD9\xC5 \xCF\xD0\xC3\xC9\xC9
+ # Проверяем все переданные опции
while (my ($key, $value) = each %arg) {
next unless exists $opts{$key};
$self->{$key} = $value;
delete $opts{$key};
}
- # \xE9 \xCF\xD0\xD2\xC5\xC4\xC5\xCC\xC9\xCD \xD5\xCD\xCF\xCC\xDE\xC1\xCE\xC9\xD1
+ # И определим умолчания
while (my ($key, $value) = each %opts) {
next unless defined $value;
$self->{$key} = $value unless exists $self->{$key};
@@ -129,18 +127,16 @@
(
{
Output => \*STDOUT,
- InputCharset => 'cp1251', # \xEB\xC1\xCB\xCF\xCA \xD0\xD2\xC9\xCE\xD1\xD4\xD8 \xD7\xC8\xCF\xC4\xCE\xD9\xCD \xC5\xD3\xCC\xC9 \xCE\xC5\xD4 ansicpg
- StrictInputCharset => '', # \xE5\xD3\xCC\xC9 \xDA\xC1\xC4\xC1\xCE - \xD4\xCF \xD0\xCC\xC5\xD7\xC1\xD4\xD8 \xCE\xC1 InCharset
- OutputCharset => 'koi8-r', # \xF7 \xCB\xC1\xCB\xCF\xCD charset-\xC5 \xD7\xD9\xD7\xCF\xC4\xC9\xD4\xD8
+ InputCharset => 'cp1251', # Какой принять входным если нет ansicpg
+ StrictInputCharset => '', # Если задан - то плевать на InCharset
+ OutputCharset => 'utf-8', # В каком charset-е выводить
CatdocCharsets => '/usr/local/lib/catdoc',
},
@_
);
set_top_output_to($self->{Output});
set_catdoc_libs($self->{CatdocCharsets});
- require Communiware::Charset;
- Communiware::Charset::init_charset($self->{OutputCharset})
- unless ($Communiware::Charset::replace_string);
+
$self;
}
@@ -163,83 +159,37 @@
###########################################################################
-# \xF0\xCF\xC4\xC4\xC5\xD2\xD6\xCB\xC1 \xD0\xC5\xD2\xC5\xCB\xCF\xC4\xC9\xD2\xCF\xD7\xCF\xCB
+# Поддержка перекодировок
+use Encode;
use vars qw/
- $InMapper
$InCharset
- $OutMapper
$OutCharset
- @directMapper
$CatdocCharsets
/;
-# \xE7\xC4\xC5 \xCC\xC5\xD6\xC1\xD4 \xC6\xC1\xCA\xCC\xD9 \xDE\xC1\xD2\xD3\xC5\xD4\xCF\xD7
-($InMapper, $OutMapper, $InCharset, $OutCharset, $CatdocCharsets) =
- (undef, undef, '', '', '');
+# Где лежат файлы чарсетов
+($InCharset, $OutCharset, $CatdocCharsets) =
+ ('', '', '');
sub set_catdoc_libs {$CatdocCharsets = $_[0]}
-sub set_input_charset {
- my $charset= shift;
- return if ($InCharset eq $charset);
- my ($code,$unicode);
- my $chrsname = "$CatdocCharsets/$charset.txt";
- die "Cannot set input charset to $charset, no $chrsname" unless -f $chrsname;
- open CHARSET, $chrsname;
- $InMapper = {};
- while (<CHARSET>) {
- next unless /^\s*(0x[0-9A-Fa-f]{2})\s+((0x)?[0-9A-Fa-f]{4})/;
- $code = hex($1); $unicode = hex($2);
- $InMapper->{$unicode}=chr($code);
- $directMapper[$code] = $unicode;
- }
- close CHARSET;
- $InCharset = $charset;
-}
+sub from_unicode {
+ return $_[0];
+# Этого момента я не понял... Что бы мы не возвращали, все равно все работает правильно :-/
+# Разбираться пока леть... Работает же ;-)
+# Шаплов.
-sub set_output_charset {
- my $charset= shift;
- return if ($OutCharset eq $charset);
- my ($code,$unicode);
- my $chrsname = "$CatdocCharsets/$charset.txt";
- die "Cannot set output charset to $charset, no $chrsname" unless -f $chrsname;
- open CHARSET, $chrsname;
- $OutMapper = {};
- while (<CHARSET>) {
- next unless /^\s*(0x[0-9A-Fa-f]{2})\s+((0x)?[0-9A-Fa-f]{4})/;
- $code = chr(hex($1)); $unicode = hex($2);
- $OutMapper->{$unicode} =$code;
- }
- close CHARSET;
- $OutCharset = $charset;
+# return "b";
+# return ($InMapper->{$_[0]} || '"');
}
-sub make_direct_map {
- my $i;
- foreach $i (grep {defined} @directMapper) {
-
- $i = $OutMapper->{$i} || '"';
- }
-}
-sub from_unicode {
- return ($InMapper->{$_[0]} || '"');
-}
-
-sub recode_char {
- my $char= $directMapper[ord($_[0])];
- $char = $Communiware::Charset::escaping{$char}
- if exists $Communiware::Charset::escaping{$char};
- return $char;
-}
-
sub recode_string {
- local $_ = shift;
- s/([\200-\377])/$directMapper[ord($1)]/eg;
- s/([$Communiware::Charset::replace_string])/$Communiware::Charset::escaping{$1}/eg;
-
- return $_;
+ my $in_str = shift;
+ my $utf8_str = Encode::decode($InCharset,$in_str);
+ my $out_str = Encode::encode($OutCharset,$utf8_str,Encode::FB_XMLCREF);
+ return $out_str;
}
###########################################################################
# Utils
@@ -317,7 +267,7 @@
# the default prints on the selected output filehandle
sub flush_top_output {
- # \xF0\xC5\xDE\xC1\xD4\xC1\xD4\xD8 \xC9\xCC\xC9 \xCB\xC1\xCB \xC5\xD3\xD4\xD8, \xC9\xCC\xC9 \xD3 \xD0\xC5\xD2\xC5\xCB\xCF\xC4\xC9\xD2\xCF\xD7\xCB\xCF\xCA
+ # Печатать или как есть, или с перекодировкой
my $o = ($InCharset eq $OutCharset) ?
$output_stack[TOP] : recode_string( $output_stack[TOP]);
print $o;
@@ -1252,7 +1202,6 @@
}
use constant PARSE_START_END => 0;
-
sub parse_start {
my $self = shift;
@@ -1261,10 +1210,12 @@
%fonttbl = ();
%colortbl = ();
%stylesheet = ();
-
- set_input_charset($self->{StrictInputCharset} || $self->{InputCharset});
- set_output_charset($self->{OutputCharset});
- make_direct_map();
+ $InCharset = $self->{StrictInputCharset} || $self->{InputCharset};
+ $OutCharset = $self->{OutputCharset};
+
+# set_input_charset($self->{StrictInputCharset} || $self->{InputCharset});
+# set_output_charset($self->{OutputCharset});
+# make_direct_map();
push_output();
if (defined (my $action = $do_on_event{'document'})) {
$event = 'start';
@@ -1273,7 +1224,6 @@
flush_top_output();
push_output();
}
-
sub parse_end {
my $self = shift;
my $action = '';
Modified: trunk/fb2-perl-tools/RTF/HTML/ansi
===================================================================
--- trunk/fb2-perl-tools/RTF/HTML/ansi 2007-09-04 12:09:14 UTC (rev 50)
+++ trunk/fb2-perl-tools/RTF/HTML/ansi 2007-09-04 12:11:02 UTC (rev 51)
@@ -25,8 +25,8 @@
93 ``
94 ''
95 ·
-96 -
-97 --
+96 –
+97 —
98 ~
99 [tm]
9a s
Modified: trunk/fb2-perl-tools/rtf2html
===================================================================
--- trunk/fb2-perl-tools/rtf2html 2007-09-04 12:09:14 UTC (rev 50)
+++ trunk/fb2-perl-tools/rtf2html 2007-09-04 12:11:02 UTC (rev 51)
@@ -74,13 +74,8 @@
=cut
require 5.004;
-use lib qw(/cmw/perllib /cmw/perllib/i386-linux-thread-multi);
use strict;
-BEGIN {
- delete $ENV{MOD_PERL};
-};
-
use File::Basename;
use Getopt::Long;
@@ -134,16 +129,17 @@
$opt{tables} and $par{CatdocCharsets} = $opt{tables};
-if (defined $par{OutputCharset} && !-f "$par{CatdocCharsets}/$par{OutputCharset}.txt") {
- open F, "$par{CatdocCharsets}/charset.map" or die "$par{CatdocCharsets}/charset.map:$!";
- while (<F>) {
- next if /^\s*#/ || /^\s*$/;
- my ($mime_name,$table_name) = split;
- $par{OutputCharset}=$table_name if $mime_name eq $par{OutputCharset};
- }
-}
+#if (defined $par{OutputCharset} && !-f "$par{CatdocCharsets}/$par{OutputCharset}.txt") {
+# open F, "$par{CatdocCharsets}/charset.map" or die "$par{CatdocCharsets}/charset.map:$!";
+# while (<F>) {
+# next if /^\s*#/ || /^\s*$/;
+# my ($mime_name,$table_name) = split;
+# $par{OutputCharset}=$table_name if $mime_name eq $par{OutputCharset};
+# }
+# }
-die "Unknown output charset $par{OutputCharset}" if $par{OutputCharset} && ! -f "$par{CatdocCharsets}/$par{OutputCharset}.txt";
+# die "Unknown output charset $par{OutputCharset}" if $par{OutputCharset} && ! -f "$par{CatdocCharsets}/$par{OutputCharset}.txt";
+
unless (defined $ARGV[0]) {
# stdin -> stdout
$cnv = new RTF::HTML::Converter(%par);
@@ -163,8 +159,8 @@
}
-# \xF0\xD2\xC5\xCF\xC2\xD2\xC1\xDA\xCF\xD7\xC1\xCE\xC9\xC5 \xCB\xC1\xD2\xD4\xC9\xCE\xCF\xCB - \xD4\xCF\xCC\xD8\xCB\xCF \xC5\xD3\xCC\xC9 \xC9\xC8 \xCB\xCF\xCE\xD7\xC5\xD2\xD4\xC1\xC3\xC9\xD1 \xD0\xCF\xC4\xC4\xC5\xD2\xD6\xC9\xD7\xC1\xC5\xD4\xD3\xD1 \xD7 \xD4\xC5\xCB\xD5\xDD\xC5\xCA
-# \xCB\xCF\xCE\xC6\xC9\xC7\xD5\xD2\xC1\xC3\xC9\xC9
+# Преобразование картинок - только если их конвертация поддерживается в текущей
+# конфигурации
if ($par{ImageDir} ne 'NONE') {
my %job = $cnv->files2convert();
@@ -173,7 +169,7 @@
next unless $to =~ /\.png$/;
die "No source file $from" unless -f $from;
- # \xF5\xC4\xC1\xCC\xD1\xC5\xCD dst
+ # Удаляем dst
unlink $to;
die "Dst file $to cannot be deleted before converting" if -f $to;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sh...@us...> - 2008-01-26 22:41:33
|
Revision: 54
http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=54&view=rev
Author: shaplov
Date: 2008-01-26 14:41:33 -0800 (Sat, 26 Jan 2008)
Log Message:
-----------
Small script to check if file is a valid fb2-book
Added Paths:
-----------
trunk/fb2-perl-tools/XSD/
trunk/fb2-perl-tools/XSD/FB2.0/
trunk/fb2-perl-tools/XSD/FB2.0/FictionBook2.xsd
trunk/fb2-perl-tools/XSD/FB2.0/FictionBookGenres.xsd
trunk/fb2-perl-tools/XSD/FB2.0/FictionBookLang.xsd
trunk/fb2-perl-tools/XSD/FB2.0/FictionBookLinks.xsd
trunk/fb2-perl-tools/XSD/FB2.1/
trunk/fb2-perl-tools/XSD/FB2.1/FictionBook.xsd
trunk/fb2-perl-tools/XSD/FB2.1/FictionBook2.1.xsd
trunk/fb2-perl-tools/XSD/FB2.1/FictionBookGenres.xsd
trunk/fb2-perl-tools/XSD/FB2.1/FictionBookLang.xsd
trunk/fb2-perl-tools/XSD/FB2.1/FictionBookLinks.xsd
trunk/fb2-perl-tools/fb2validate
Added: trunk/fb2-perl-tools/XSD/FB2.0/FictionBook2.xsd
===================================================================
--- trunk/fb2-perl-tools/XSD/FB2.0/FictionBook2.xsd (rev 0)
+++ trunk/fb2-perl-tools/XSD/FB2.0/FictionBook2.xsd 2008-01-26 22:41:33 UTC (rev 54)
@@ -0,0 +1,1061 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- edited with XML Spy v4.4 U (http://www.xmlspy.com) by Dmitry Gribov (DDS) -->
+
+<xs:schema targetNamespace="http://www.gribuser.ru/xml/fictionbook/2.0" xmlns="http://www.gribuser.ru/xml/fictionbook/2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:genre="http://www.gribuser.ru/xml/fictionbook/2.0/genres" elementFormDefault="qualified" attributeFormDefault="unqualified">
+
+ <xs:import namespace="http://www.w3.org/1999/xlink" schemaLocation="FictionBookLinks.xsd"/>
+
+ <xs:import namespace="http://www.gribuser.ru/xml/fictionbook/2.0/genres" schemaLocation="FictionBookGenres.xsd"/>
+
+ <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="FictionBookLang.xsd"/>
+
+ <xs:element name="FictionBook">
+
+ <xs:annotation>
+
+ <xs:documentation>Root element</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:complexType>
+
+ <xs:sequence>
+
+ <xs:element name="stylesheet" minOccurs="0" maxOccurs="unbounded">
+
+ <xs:annotation>
+
+ <xs:documentation>This element contains an arbitrary stylesheet that is intepreted by a some processing programs, e.g. text/css stylesheets can be used by XSLT stylesheets to generate better looking html</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:complexType>
+
+ <xs:simpleContent>
+
+ <xs:extension base="xs:string">
+
+ <xs:attribute name="type" type="xs:string" use="required"/>
+
+ </xs:extension>
+
+ </xs:simpleContent>
+
+ </xs:complexType>
+
+ </xs:element>
+
+ <xs:element name="description">
+
+ <xs:complexType>
+
+ <xs:sequence>
+
+ <xs:element name="title-info">
+
+ <xs:annotation>
+
+ <xs:documentation>Generic information about the book</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:complexType>
+
+ <xs:sequence>
+
+ <xs:element name="genre" maxOccurs="unbounded">
+
+ <xs:annotation>
+
+ <xs:documentation>Genre of this book, with the optional match percentage</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:complexType>
+
+ <xs:simpleContent>
+
+ <xs:extension base="genre:genreType">
+
+ <xs:attribute name="match" type="xs:integer" use="optional" default="100"/>
+
+ </xs:extension>
+
+ </xs:simpleContent>
+
+ </xs:complexType>
+
+ </xs:element>
+
+ <xs:element name="author" maxOccurs="unbounded">
+
+ <xs:annotation>
+
+ <xs:documentation>Author(s) of this book</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:complexType>
+
+ <xs:complexContent>
+
+ <xs:extension base="authorType"/>
+
+ </xs:complexContent>
+
+ </xs:complexType>
+
+ </xs:element>
+
+ <xs:element name="book-title" type="textFieldType">
+
+ <xs:annotation>
+
+ <xs:documentation>Book title</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="annotation" type="annotationType" minOccurs="0">
+
+ <xs:annotation>
+
+ <xs:documentation>Annotation for this book</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="keywords" type="textFieldType" minOccurs="0">
+
+ <xs:annotation>
+
+ <xs:documentation>Any keywords for this book, intended for use in search engines</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="date" type="dateType" minOccurs="0">
+
+ <xs:annotation>
+
+ <xs:documentation>Date this book was written, can be not exact, e.g. 1863-1867. If an optional attribute is present, then it should contain some computer-readable date from the interval for use by search and indexingengines</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="coverpage" minOccurs="0">
+
+ <xs:annotation>
+
+ <xs:documentation>Any coverpage items, currently only images</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:complexType>
+
+ <xs:sequence>
+
+ <xs:element name="image" type="imageType" maxOccurs="unbounded"/>
+
+ </xs:sequence>
+
+ </xs:complexType>
+
+ </xs:element>
+
+ <xs:element name="lang" type="xs:language"/>
+
+ <xs:element name="src-lang" type="xs:language" minOccurs="0">
+
+ <xs:annotation>
+
+ <xs:documentation>Book's source language if this is a translation</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="translator" type="authorType" minOccurs="0" maxOccurs="unbounded">
+
+ <xs:annotation>
+
+ <xs:documentation>Translators if this is a translation</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="sequence" type="sequenceType" minOccurs="0" maxOccurs="unbounded">
+
+ <xs:annotation>
+
+ <xs:documentation>Any sequences this book might be part of</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ </xs:sequence>
+
+ </xs:complexType>
+
+ </xs:element>
+
+ <xs:element name="document-info">
+
+ <xs:annotation>
+
+ <xs:documentation>Information about this particular (xml) document</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:complexType>
+
+ <xs:sequence>
+
+ <xs:element name="author" type="authorType" maxOccurs="unbounded">
+
+ <xs:annotation>
+
+ <xs:documentation>Author(s) of this particular document</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="program-used" type="textFieldType" minOccurs="0">
+
+ <xs:annotation>
+
+ <xs:documentation>Any software used in preparation of this document, in free format</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="date" type="dateType">
+
+ <xs:annotation>
+
+ <xs:documentation>Date this document was created, same guidelines as in the <title-info> section apply</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="src-url" type="xs:string" minOccurs="0" maxOccurs="unbounded">
+
+ <xs:annotation>
+
+ <xs:documentation>Source URL if this document is a conversion of some other (online) document</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="src-ocr" type="textFieldType" minOccurs="0">
+
+ <xs:annotation>
+
+ <xs:documentation>Author of the original (online) document, if this is a conversion</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="id" type="xs:token">
+
+ <xs:annotation>
+
+ <xs:documentation>this is a unique identifier for a document. this must not change unless you make substantial updates to the document</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="version" type="xs:float">
+
+ <xs:annotation>
+
+ <xs:documentation>Document version, in free format, should be incremented if the document is changed and re-released to the public</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="history" type="annotationType" minOccurs="0"/>
+
+ </xs:sequence>
+
+ </xs:complexType>
+
+ </xs:element>
+
+ <xs:element name="publish-info" minOccurs="0">
+
+ <xs:annotation>
+
+ <xs:documentation>Information about some paper/outher published document, that was used as a source of this xml document</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:complexType>
+
+ <xs:sequence>
+
+ <xs:element name="book-name" type="textFieldType" minOccurs="0">
+
+ <xs:annotation>
+
+ <xs:documentation>Original (paper) book name</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="publisher" type="textFieldType" minOccurs="0">
+
+ <xs:annotation>
+
+ <xs:documentation>Original (paper) book publisher</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="city" type="textFieldType" minOccurs="0">
+
+ <xs:annotation>
+
+ <xs:documentation>City where the original (paper) book was published</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="year" type="xs:gYear" minOccurs="0">
+
+ <xs:annotation>
+
+ <xs:documentation>Year of the original (paper) publication</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="isbn" type="textFieldType" minOccurs="0"/>
+
+ <xs:element name="sequence" type="sequenceType" minOccurs="0" maxOccurs="unbounded"/>
+
+ </xs:sequence>
+
+ </xs:complexType>
+
+ </xs:element>
+
+ <xs:element name="custom-info" minOccurs="0" maxOccurs="unbounded">
+
+ <xs:annotation>
+
+ <xs:documentation>Any other information about the book/document that didnt fit in the above groups</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:complexType>
+
+ <xs:simpleContent>
+
+ <xs:extension base="textFieldType">
+
+ <xs:attribute name="info-type" type="xs:string" use="required"/>
+
+ </xs:extension>
+
+ </xs:simpleContent>
+
+ </xs:complexType>
+
+ </xs:element>
+
+ </xs:sequence>
+
+ </xs:complexType>
+
+ </xs:element>
+
+ <xs:element name="body" maxOccurs="unbounded">
+
+ <xs:annotation>
+
+ <xs:documentation>Main content of the book, multiple bodies are used for additional information, like footnotes, that do not appear in the main book flow. The first body is presented to the reader by default, and content in the other bodies should be accessible by hyperlinks. Name attribute should describe the meaning of this body, this is optional for the main body.</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:complexType>
+
+ <xs:sequence>
+
+ <xs:element name="image" type="imageType" minOccurs="0">
+
+ <xs:annotation>
+
+ <xs:documentation>Image to be displayed at the top of this section</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="title" type="titleType" minOccurs="0">
+
+ <xs:annotation>
+
+ <xs:documentation>A fancy title for the entire book, should be used if the simple text version in <description> is not adequate, e.g. the book title has multiple paragraphs and/or character styles</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="epigraph" type="epigraphType" minOccurs="0" maxOccurs="unbounded">
+
+ <xs:annotation>
+
+ <xs:documentation>Epigraph(s) for the entire book, if any</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="section" type="sectionType" maxOccurs="unbounded"/>
+
+ </xs:sequence>
+
+ <xs:attribute name="name" type="xs:string" use="optional"/>
+
+ <xs:attribute ref="xml:lang"/>
+
+ </xs:complexType>
+
+ </xs:element>
+
+ <xs:element name="binary" minOccurs="0" maxOccurs="unbounded">
+
+ <xs:annotation>
+
+ <xs:documentation>Any binary data that is required for the presentation of this book in base64 format. Currently only images are used.</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:complexType>
+
+ <xs:simpleContent>
+
+ <xs:extension base="xs:base64Binary">
+
+ <xs:attribute name="content-type" type="xs:string" use="required"/>
+
+ <xs:attribute name="id" type="xs:ID" use="required"/>
+
+ </xs:extension>
+
+ </xs:simpleContent>
+
+ </xs:complexType>
+
+ </xs:element>
+
+ </xs:sequence>
+
+ </xs:complexType>
+
+ </xs:element>
+
+ <xs:complexType name="authorType">
+
+ <xs:annotation>
+
+ <xs:documentation>Information about a single author</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:choice>
+
+ <xs:sequence>
+
+ <xs:element name="first-name" type="textFieldType"/>
+
+ <xs:element name="middle-name" type="textFieldType" minOccurs="0"/>
+
+ <xs:element name="last-name" type="textFieldType"/>
+
+ <xs:element name="nickname" type="textFieldType" minOccurs="0"/>
+
+ <xs:element name="home-page" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
+
+ <xs:element name="email" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
+
+ </xs:sequence>
+
+ <xs:sequence>
+
+ <xs:element name="nickname" type="textFieldType"/>
+
+ <xs:element name="home-page" type="xs:string" minOccurs="0"/>
+
+ <xs:element name="email" type="xs:string" minOccurs="0"/>
+
+ </xs:sequence>
+
+ </xs:choice>
+
+ </xs:complexType>
+
+ <xs:complexType name="textFieldType">
+
+ <xs:simpleContent>
+
+ <xs:extension base="xs:string">
+
+ <xs:attribute ref="xml:lang"/>
+
+ </xs:extension>
+
+ </xs:simpleContent>
+
+ </xs:complexType>
+
+ <xs:complexType name="dateType">
+
+ <xs:annotation>
+
+ <xs:documentation>A human readable date, maybe not exact, with an optional computer readable variant</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:simpleContent>
+
+ <xs:extension base="xs:string">
+
+ <xs:attribute name="value" type="xs:date" use="optional"/>
+
+ <xs:attribute ref="xml:lang"/>
+
+ </xs:extension>
+
+ </xs:simpleContent>
+
+ </xs:complexType>
+
+ <xs:complexType name="titleType">
+
+ <xs:annotation>
+
+ <xs:documentation>A title, used in sections, poems and body elements</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:choice minOccurs="0" maxOccurs="unbounded">
+
+ <xs:element name="p" type="pType"/>
+
+ <xs:element name="empty-line"/>
+
+ </xs:choice>
+
+ <xs:attribute ref="xml:lang"/>
+
+ </xs:complexType>
+
+ <xs:complexType name="imageType">
+
+ <xs:annotation>
+
+ <xs:documentation>An empty element with an image name as an attribute</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:attribute ref="xlink:type"/>
+
+ <xs:attribute ref="xlink:href"/>
+
+ <xs:attribute name="alt" type="xs:string" use="optional"/>
+
+ </xs:complexType>
+
+ <xs:complexType name="pType" mixed="true">
+
+ <xs:annotation>
+
+ <xs:documentation>A basic paragraph, may include simple formatting inside</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:complexContent mixed="true">
+
+ <xs:extension base="styleType">
+
+ <xs:attribute name="id" type="xs:ID" use="optional"/>
+
+ <xs:attribute name="style" type="xs:string" use="optional"/>
+
+ </xs:extension>
+
+ </xs:complexContent>
+
+ </xs:complexType>
+
+ <xs:complexType name="citeType">
+
+ <xs:annotation>
+
+ <xs:documentation>A citation with an optional citation author at the end</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:sequence>
+
+ <xs:choice minOccurs="0" maxOccurs="unbounded">
+
+ <xs:element name="p" type="pType"/>
+
+ <xs:element name="poem" type="poemType"/>
+
+ <xs:element name="empty-line"/>
+
+ </xs:choice>
+
+ <xs:element name="text-author" type="textFieldType" minOccurs="0" maxOccurs="unbounded"/>
+
+ </xs:sequence>
+
+ <xs:attribute name="id" type="xs:ID" use="optional"/>
+
+ <xs:attribute ref="xml:lang"/>
+
+ </xs:complexType>
+
+ <xs:complexType name="poemType">
+
+ <xs:annotation>
+
+ <xs:documentation>A poem</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:sequence>
+
+ <xs:element name="title" type="titleType" minOccurs="0">
+
+ <xs:annotation>
+
+ <xs:documentation>Poem title</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="epigraph" type="epigraphType" minOccurs="0" maxOccurs="unbounded">
+
+ <xs:annotation>
+
+ <xs:documentation>Poem epigraph(s), if any</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="stanza" maxOccurs="unbounded">
+
+ <xs:annotation>
+
+ <xs:documentation>Each poem should have at least one stanza. Stanzas are usually separated with empty lines by user agents.</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:complexType>
+
+ <xs:sequence>
+
+ <xs:element name="title" type="titleType" minOccurs="0"/>
+
+ <xs:element name="subtitle" type="pType" minOccurs="0"/>
+
+ <xs:element name="v" type="pType" maxOccurs="unbounded">
+
+ <xs:annotation>
+
+ <xs:documentation>An individual line in a stanza</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ </xs:sequence>
+
+ <xs:attribute ref="xml:lang"/>
+
+ </xs:complexType>
+
+ </xs:element>
+
+ <xs:element name="text-author" type="textFieldType" minOccurs="0" maxOccurs="unbounded"/>
+
+ <xs:element name="date" type="dateType" minOccurs="0">
+
+ <xs:annotation>
+
+ <xs:documentation>Date this poem was written.</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ </xs:sequence>
+
+ <xs:attribute name="id" type="xs:ID" use="optional"/>
+
+ <xs:attribute ref="xml:lang"/>
+
+ </xs:complexType>
+
+ <xs:complexType name="epigraphType">
+
+ <xs:annotation>
+
+ <xs:documentation>An epigraph</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:sequence>
+
+ <xs:choice minOccurs="0" maxOccurs="unbounded">
+
+ <xs:element name="p" type="pType"/>
+
+ <xs:element name="poem" type="poemType"/>
+
+ <xs:element name="cite" type="citeType"/>
+
+ <xs:element name="empty-line"/>
+
+ </xs:choice>
+
+ <xs:element name="text-author" type="textFieldType" minOccurs="0" maxOccurs="unbounded"/>
+
+ </xs:sequence>
+
+ <xs:attribute name="id" type="xs:ID" use="optional"/>
+
+ </xs:complexType>
+
+ <xs:complexType name="annotationType">
+
+ <xs:annotation>
+
+ <xs:documentation>A cut-down version of <section> used in annotations</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:choice minOccurs="0" maxOccurs="unbounded">
+
+ <xs:element name="p" type="pType"/>
+
+ <xs:element name="poem" type="poemType"/>
+
+ <xs:element name="cite" type="citeType"/>
+
+ <xs:element name="empty-line"/>
+
+ </xs:choice>
+
+ <xs:attribute name="id" type="xs:ID" use="optional"/>
+
+ <xs:attribute ref="xml:lang"/>
+
+ </xs:complexType>
+
+ <xs:complexType name="sectionType">
+
+ <xs:annotation>
+
+ <xs:documentation>A basic block of a book, can contain more child sections or textual content</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:sequence minOccurs="0">
+
+ <xs:element name="title" type="titleType" minOccurs="0">
+
+ <xs:annotation>
+
+ <xs:documentation>Section's title</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="epigraph" type="epigraphType" minOccurs="0" maxOccurs="unbounded">
+
+ <xs:annotation>
+
+ <xs:documentation>Epigraph(s) for this section</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="image" type="imageType" minOccurs="0">
+
+ <xs:annotation>
+
+ <xs:documentation>Image to be displayed at the top of this section</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:element name="annotation" type="annotationType" minOccurs="0">
+
+ <xs:annotation>
+
+ <xs:documentation>Annotation for this section, if any</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ <xs:choice>
+
+ <xs:sequence>
+
+ <xs:element name="section" type="sectionType" maxOccurs="unbounded">
+
+ <xs:annotation>
+
+ <xs:documentation>Child sections</xs:documentation>
+
+ </xs:annotation>
+
+ </xs:element>
+
+ </xs:sequence>
+
+ <xs:sequence>
+
+ <xs:choice>
+
+ <xs:element name="p" type="pType"/>
+
+ <xs:element name="poem" type="poemType"/>
+
+ <xs:element name="subtitle" type="pType"/>
+
+ <xs:element name="cite" type="citeType"/>
+
+ <xs:element name="empty-line"/>
+
+ <xs:element name="table" type="tableType"/>
+
+ </xs:choice>
+
+ <xs:choice minOccurs="0" maxOccurs="unbounded">
+
+ <xs:element name="p" type="pType"/>
+
+ <xs:element name="image" type="imageType"/>
+
+ <xs:element name="poem" type="poemType"/>
+
+ <xs:element name="subtitle" type="pType"/>
+
+ <xs:element name="cite" type="citeType"/>
+
+ <xs:element name="empty-line"/>
+
+ <xs:element name="table" type="tableType"/>
+
+ </xs:choice>
+
+ </xs:sequence>
+
+ </xs:choice>
+
+ </xs:sequence>
+
+ <xs:attribute name="id" type="xs:ID" use="optional"/>
+
+ <xs:attribute ref="xml:lang"/>
+
+ </xs:complexType>
+
+ <xs:complexType name="styleType" mixed="true">
+
+ <xs:annotation>
+
+ <xs:documentation>Markup</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:choice minOccurs="0" maxOccurs="unbounded">
+
+ <xs:element name="strong" type="styleType"/>
+
+ <xs:element name="emphasis" type="styleType"/>
+
+ <xs:element name="style" type="namedStyleType"/>
+
+ <xs:element name="a" type="linkType"/>
+
+ <xs:element name="image" type="imageType"/>
+
+ </xs:choice>
+
+ <xs:attribute ref="xml:lang"/>
+
+ </xs:complexType>
+
+ <xs:complexType name="namedStyleType" mixed="true">
+
+ <xs:annotation>
+
+ <xs:documentation>Markup</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:choice minOccurs="0" maxOccurs="unbounded">
+
+ <xs:element name="strong" type="styleType"/>
+
+ <xs:element name="emphasis" type="styleType"/>
+
+ <xs:element name="style" type="namedStyleType"/>
+
+ <xs:element name="a" type="linkType"/>
+
+ <xs:element name="image" type="imageType"/>
+
+ </xs:choice>
+
+ <xs:attribute ref="xml:lang"/>
+
+ <xs:attribute name="name" type="xs:token" use="required"/>
+
+ </xs:complexType>
+
+ <xs:complexType name="linkType" mixed="true">
+
+ <xs:annotation>
+
+ <xs:documentation>Generic hyperlinks. Cannot be nested. Footnotes should be implemented by links referring to additional bodies in the same document</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:choice minOccurs="0" maxOccurs="unbounded">
+
+ <xs:element name="strong" type="styleLinkType"/>
+
+ <xs:element name="emphasis" type="styleLinkType"/>
+
+ <xs:element name="style" type="styleLinkType"/>
+
+ </xs:choice>
+
+ <xs:attribute ref="xlink:type" use="optional"/>
+
+ <xs:attribute ref="xlink:href" use="required"/>
+
+ <xs:attribute name="type" type="xs:token" use="optional"/>
+
+ </xs:complexType>
+
+ <xs:complexType name="styleLinkType" mixed="true">
+
+ <xs:annotation>
+
+ <xs:documentation>Markup</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:choice minOccurs="0" maxOccurs="unbounded">
+
+ <xs:element name="strong" type="styleLinkType"/>
+
+ <xs:element name="emphasis" type="styleLinkType"/>
+
+ <xs:element name="style" type="styleLinkType"/>
+
+ </xs:choice>
+
+ </xs:complexType>
+
+ <xs:complexType name="sequenceType">
+
+ <xs:annotation>
+
+ <xs:documentation>Book sequences</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:sequence>
+
+ <xs:element name="sequence" type="sequenceType" minOccurs="0" maxOccurs="unbounded"/>
+
+ </xs:sequence>
+
+ <xs:attribute name="name" type="xs:string" use="required"/>
+
+ <xs:attribute name="number" type="xs:integer" use="optional"/>
+
+ <xs:attribute ref="xml:lang"/>
+
+ </xs:complexType>
+
+ <xs:complexType name="tableType">
+
+ <xs:annotation>
+
+ <xs:documentation>Basic html-like tables</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:sequence>
+
+ <xs:element name="tr" maxOccurs="unbounded">
+
+ <xs:complexType>
+
+ <xs:sequence>
+
+ <xs:element name="td" type="pType" maxOccurs="unbounded"/>
+
+ </xs:sequence>
+
+ <xs:attribute name="align" type="alignType" use="optional" default="left"/>
+
+ </xs:complexType>
+
+ </xs:element>
+
+ </xs:sequence>
+
+ </xs:complexType>
+
+ <xs:simpleType name="alignType">
+
+ <xs:restriction base="xs:token">
+
+ <xs:enumeration value="left"/>
+
+ <xs:enumeration value="right"/>
+
+ <xs:enumeration value="center"/>
+
+ </xs:restriction>
+
+ </xs:simpleType>
+
+</xs:schema>
\ No newline at end of file
Added: trunk/fb2-perl-tools/XSD/FB2.0/FictionBookGenres.xsd
===================================================================
--- trunk/fb2-perl-tools/XSD/FB2.0/FictionBookGenres.xsd (rev 0)
+++ trunk/fb2-perl-tools/XSD/FB2.0/FictionBookGenres.xsd 2008-01-26 22:41:33 UTC (rev 54)
@@ -0,0 +1,393 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- edited with XML Spy v4.2 U (http://www.xmlspy.com) by * (*) -->
+<xs:schema targetNamespace="http://www.gribuser.ru/xml/fictionbook/2.0/genres" xmlns="http://www.gribuser.ru/xml/fictionbook/2.0/genres" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
+ <xs:simpleType name="genreType">
+ <xs:restriction base="xs:token">
+ <xs:enumeration value="architecture"/>
+ <xs:enumeration value="art"/>
+ <xs:enumeration value="art_instr"/>
+ <xs:enumeration value="artists"/>
+ <xs:enumeration value="fashion"/>
+ <xs:enumeration value="graph_design"/>
+ <xs:enumeration value="performance"/>
+ <xs:enumeration value="photography"/>
+ <xs:enumeration value="people"/>
+ <xs:enumeration value="biography"/>
+ <xs:enumeration value="biogr_arts"/>
+ <xs:enumeration value="biogr_ethnic"/>
+ <xs:enumeration value="biogr_family"/>
+ <xs:enumeration value="biogr_historical"/>
+ <xs:enumeration value="biogr_leaders"/>
+ <xs:enumeration value="biogr_professionals"/>
+ <xs:enumeration value="biogr_sports"/>
+ <xs:enumeration value="biogr_travel"/>
+ <xs:enumeration value="business"/>
+ <xs:enumeration value="biz_accounting"/>
+ <xs:enumeration value="biz_beogr"/>
+ <xs:enumeration value="biz_life"/>
+ <xs:enumeration value="biz_careers"/>
+ <xs:enumeration value="biz_economics"/>
+ <xs:enumeration value="biz_finance"/>
+ <xs:enumeration value="biz_international"/>
+ <xs:enumeration value="biz_professions"/>
+ <xs:enumeration value="biz_investing"/>
+ <xs:enumeration value="biz_management"/>
+ <xs:enumeration value="biz_sales"/>
+ <xs:enumeration value="biz_personal_fin"/>
+ <xs:enumeration value="biz_ref"/>
+ <xs:enumeration value="biz_small_biz"/>
+ <xs:enumeration value="child_3"/>
+ <xs:enumeration value="child_4"/>
+ <xs:enumeration value="child_9"/>
+ <xs:enumeration value="child_animals"/>
+ <xs:enumeration value="child_art"/>
+ <xs:enumeration value="child_computers"/>
+ <xs:enumeration value="child_edu"/>
+ <xs:enumeration value="child_history"/>
+ <xs:enumeration value="child_obsessions"/>
+ <xs:enumeration value="child_people"/>
+ <xs:enumeration value="child_characters"/>
+ <xs:enumeration value="child_ref"/>
+ <xs:enumeration value="child_religion"/>
+ <xs:enumeration value="child_nature"/>
+ <xs:enumeration value="child_series"/>
+ <xs:enumeration value="child_sports"/>
+ <xs:enumeration value="chris_bibles"/>
+ <xs:enumeration value="chris_pravoslavie"/>
+ <xs:enumeration value="chris_catholicism"/>
+ <xs:enumeration value="chris_living"/>
+ <xs:enumeration value="chris_history"/>
+ <xs:enumeration value="chris_clergy"/>
+ <xs:enumeration value="chris_edu"/>
+ <xs:enumeration value="chris_evangelism"/>
+ <xs:enumeration value="chris_fiction"/>
+ <xs:enumeration value="chris_holidays"/>
+ <xs:enumeration value="chris_jesus"/>
+ <xs:enumeration value="chris_mormonism"/>
+ <xs:enumeration value="chris_orthodoxy"/>
+ <xs:enumeration value="chris_protestantism"/>
+ <xs:enumeration value="chris_ref"/>
+ <xs:enumeration value="chris_theology"/>
+ <xs:enumeration value="chris_devotion"/>
+ <xs:enumeration value="computers"/>
+ <xs:enumeration value="comp_office"/>
+ <xs:enumeration value="comp_cert"/>
+ <xs:enumeration value="comp_games"/>
+ <xs:enumeration value="comp_sci"/>
+ <xs:enumeration value="comp_db"/>
+ <xs:enumeration value="comp_biz"/>
+ <xs:enumeration value="comp_graph"/>
+ <xs:enumeration value="comp_hardware"/>
+ <xs:enumeration value="comp_microsoft"/>
+ <xs:enumeration value="comp_networking"/>
+ <xs:enumeration value="comp_os"/>
+ <xs:enumeration value="comp_programming"/>
+ <xs:enumeration value="comp_software"/>
+ <xs:enumeration value="comp_www"/>
+ <xs:enumeration value="cooking"/>
+ <xs:enumeration value="cook_baking"/>
+ <xs:enumeration value="cook_can"/>
+ <xs:enumeration value="cook_art"/>
+ <xs:enumeration value="cook_drink"/>
+ <xs:enumeration value="cook_gastronomy"/>
+ <xs:enumeration value="cook_meals"/>
+ <xs:enum...
[truncated message content] |
|
From: <sh...@us...> - 2008-01-27 17:52:55
|
Revision: 55
http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=55&view=rev
Author: shaplov
Date: 2008-01-27 09:52:52 -0800 (Sun, 27 Jan 2008)
Log Message:
-----------
fb2_to_many_html by Gribuser, as is.
Just renamed files and removed dos style line ends.
Added Paths:
-----------
trunk/fb2-perl-tools/XSL/
trunk/fb2-perl-tools/XSL/fb22htmls.xsl
trunk/fb2-perl-tools/fb2/Convert/
trunk/fb2-perl-tools/fb2/Convert/Htmls.pm
trunk/fb2-perl-tools/fb22htmls
Added: trunk/fb2-perl-tools/XSL/fb22htmls.xsl
===================================================================
--- trunk/fb2-perl-tools/XSL/fb22htmls.xsl (rev 0)
+++ trunk/fb2-perl-tools/XSL/fb22htmls.xsl 2008-01-27 17:52:52 UTC (rev 55)
@@ -0,0 +1,300 @@
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fb="http://www.gribuser.ru/xml/fictionbook/2.0">
+ <xsl:output method="html" encoding="windows-1251"/>
+ <xsl:param name="PageN">1</xsl:param>
+ <xsl:param name="TotalPages">1</xsl:param>
+ <xsl:param name="BookTitle">NoName</xsl:param>
+ <xsl:param name="FileName">noname</xsl:param>
+ <xsl:template match="/*">
+ <html>
+ <head>
+ <title>
+ <xsl:value-of select="$BookTitle"/>
+ </title>
+ <style type="text/css" media="screen">
+ A { color : #0002CC }
+ A:HOVER { color : #BF0000 }
+ BODY { background-color : #FEFEFE; color : #000000; font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; text-align : justify }
+ H1{ font-size : 160%; font-style : normal; font-weight : bold; text-align : left; text-transform : capitalize; border : 1px solid Black; background-color : #E7E7E7; text-transform : capitalize; margin-left : 0px; padding-left : 0.5em; }
+ H2{ font-size : 130%; font-style : normal; font-weight : bold; text-align : left; text-transform : capitalize; background-color : #EEEEEE; border : 1px solid Gray; text-transform : capitalize; padding-left : 1em; }
+ H3{ font-size : 110%; font-style : normal; font-weight : bold; text-align : left; background-color : #F1F1F1; border : 1px solid Silver; text-transform : capitalize; padding-left : 1.5em;}
+ H4{ font-size : 100%; font-style : normal; font-weight : bold; text-align : left padding-left : 0.5em; text-transform : capitalize; border : 1px solid Gray; background-color : #F4F4F4; padding-left : 2em;}
+ H5{ font-size : 100%; font-style : italic; font-weight : bold; text-align : left; text-transform : capitalize;border : 1px solid Gray; background-color : #F4F4F4; padding-left : 2.5em;}
+ H6{ font-size : 100%; font-style : italic; font-weight : normal; text-align : left; text-transform : capitalize;border : 1px solid Gray; background-color : #F4F4F4; padding-left : 2.5em;}
+ SMALL{ font-size : 80% }
+ BLOCKQUOTE{ margin : 0 1em 0.2em 4em }
+ HR{ color : Black }
+ UL{ padding-left : 1em; margin-left: 0}
+ .epigraph{width:50%; margin-left : 35%;}
+ </style>
+ <style type="text/css" media="print">
+ A { color : #0002CC }
+ A:HOVER { color : #BF0000 }
+ BODY { background-color : #FEFEFE; color : #000000; font-family : "Times New Roman", Times, serif; text-align : justify }
+ H1{ font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 160%; font-style : normal; font-weight : bold; text-align : left; text-transform : capitalize }
+ H2{ font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 130%; font-style : normal; font-weight : bold; text-align : left; text-transform : capitalize }
+ H3{ font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 110%; font-style : normal; font-weight : bold; text-align : left }
+ H4{ font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 100%; font-style : normal; font-weight : bold; text-align : left }
+ H5,H6{ font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 100%; font-style : italic; font-weight : normal; text-align : left; text-transform : uppercase }
+ SMALL{ font-size : 80% }
+ BLOCKQUOTE{ margin : 0 1em 0.2em 4em }
+ HR{ color : Black }
+ </style>
+ </head>
+ <body>
+ <div><xsl:call-template name="for"/></div>
+ <br/>
+ <xsl:apply-templates/>
+ <br/>
+ <div><xsl:call-template name="for"/></div>
+ </body>
+ </html>
+ </xsl:template>
+ <xsl:template match="toc-item">
+ <div>
+ <xsl:attribute name="style">padding-left: <xsl:value-of select="@deep"/>em;</xsl:attribute>
+ <a href="{$FileName}_{@n}.html"><xsl:apply-templates/></a>
+ </div>
+ </xsl:template>
+ <xsl:template match="description">
+ <xsl:apply-templates select="title-info/coverpage/image"/>
+ <h1><xsl:apply-templates select="title-info/book-title"/></h1>
+ <h2>
+ <small>
+ <xsl:for-each select="title-info/author">
+ <b>
+ <xsl:call-template name="author"/>
+ </b>
+ </xsl:for-each>
+ </small>
+ </h2>
+ <xsl:if test="title-info/sequence">
+ <p>
+ <xsl:for-each select="title-info/sequence">
+ <xsl:call-template name="sequence"/><br/>
+ </xsl:for-each>
+ </p>
+ </xsl:if>
+ <xsl:for-each select="title-info/annotation">
+ <div>
+ <xsl:call-template name="annotation"/>
+ </div>
+ <hr/>
+ </xsl:for-each>
+ </xsl:template>
+ <!-- author template -->
+ <xsl:template name="author">
+ <xsl:value-of select="first-name"/>
+ <xsl:text disable-output-escaping="no"> </xsl:text>
+ <xsl:value-of select="middle-name"/> 
+ <xsl:text disable-output-escaping="no"> </xsl:text>
+ <xsl:value-of select="last-name"/>
+ <br/>
+ </xsl:template>
+ <!-- secuence template -->
+ <xsl:template name="sequence">
+ <LI/>
+ <xsl:value-of select="@name"/>
+ <xsl:if test="@number">
+ <xsl:text disable-output-escaping="no">, #</xsl:text>
+ <xsl:value-of select="@number"/>
+ </xsl:if>
+ <xsl:if test="sequence">
+ <UL>
+ <xsl:for-each select="sequence">
+ <xsl:call-template name="sequence"/>
+ </xsl:for-each>
+ </UL>
+ </xsl:if>
+ <!-- <br/> -->
+ </xsl:template>
+ <xsl:template match="fb:subtitle">
+ <xsl:if test="@id">
+ <xsl:element name="a">
+ <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
+ </xsl:element>
+ </xsl:if>
+ <h5>
+ <xsl:apply-templates/>
+ </h5>
+ </xsl:template>
+
+ <xsl:template match="p">
+ <div align="justify"><xsl:if test="@id">
+ <xsl:element name="a">
+ <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
+ </xsl:element>
+ </xsl:if>    <xsl:apply-templates/></div>
+ </xsl:template>
+ <!-- strong -->
+ <xsl:template match="strong">
+ <b><xsl:apply-templates/></b>
+ </xsl:template>
+ <!-- emphasis -->
+ <xsl:template match="emphasis">
+ <i> <xsl:apply-templates/></i>
+ </xsl:template>
+ <!-- style -->
+ <xsl:template match="style">
+ <span class="{@name}"><xsl:apply-templates/></span>
+ </xsl:template>
+ <!-- empty-line -->
+ <xsl:template match="empty-line">
+ <br/>
+ </xsl:template>
+ <!-- link -->
+ <xsl:template match="a">
+ <xsl:choose>
+ <xsl:when test="(@type) = 'note'">
+ <xsl:element name="a">
+ <xsl:attribute name="href"><xsl:value-of select="$FileName"/>_<xsl:value-of select="$TotalPages"/>.html<xsl:value-of select="@xlink:href"/></xsl:attribute>
+ <sup>
+ <xsl:apply-templates/>
+ </sup>
+ </xsl:element>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:apply-templates/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ <!-- annotation -->
+ <xsl:template name="annotation">
+ <xsl:if test="@id">
+ <xsl:element name="a">
+ <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
+ </xsl:element>
+ </xsl:if>
+ <h3>Annotation</h3>
+ <xsl:apply-templates/>
+ </xsl:template>
+ <!-- epigraph -->
+ <xsl:template match="epigraph">
+ <blockquote class="epigraph">
+ <xsl:if test="@id">
+ <xsl:element name="a">
+ <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
+ </xsl:element>
+ </xsl:if>
+ <xsl:apply-templates/>
+ </blockquote>
+ </xsl:template>
+ <!-- epigraph/text-author -->
+ <xsl:template match="epigraph/text-author">
+ <blockquote>
+ <i><xsl:apply-templates/></i>
+ </blockquote>
+ </xsl:template>
+ <!-- cite -->
+ <xsl:template match="cite">
+ ...<blockquote><i>
+ <xsl:if test="@id">
+ <xsl:element name="a">
+ <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
+ </xsl:element>
+ </xsl:if>
+ <xsl:apply-templates/>
+ </i></blockquote>
+ </xsl:template>
+ <!-- cite/text-author -->
+ <xsl:template name="text-author">
+ <br/>
+ <i> <xsl:apply-templates/></i>
+ </xsl:template>
+ <!-- date -->
+ <xsl:template match="date">
+ <xsl:choose>
+ <xsl:when test="not(@value)">
+    <xsl:apply-templates/>
+ <br/>
+ </xsl:when>
+ <xsl:otherwise>
+    <xsl:value-of select="@value"/>
+ <br/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ <!-- poem -->
+ <xsl:template match="poem">
+ <blockquote>
+ <xsl:if test="@id">
+ <xsl:element name="a">
+ <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
+ </xsl:element>
+ </xsl:if>
+ <xsl:apply-templates/>
+ </blockquote>
+ </xsl:template>
+ <!-- poem/title -->
+<!-- <xsl:template match="poem/title">
+ <h6><xsl:apply-templates/></h6>
+ </blockquote>
+ </xsl:template> -->
+ <!-- stanza -->
+ <xsl:template match="stanza">
+ <br/>
+ <xsl:apply-templates/>
+ <br/>
+ </xsl:template>
+ <!-- v -->
+ <xsl:template match="v">
+ <xsl:if test="@id">
+ <xsl:element name="a">
+ <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
+ </xsl:element>
+ </xsl:if>
+ <xsl:apply-templates/><br/>
+ </xsl:template>
+ <!-- image -->
+ <xsl:template match="image">
+ <div align="center">
+ <img border="1">
+ <xsl:choose>
+ <xsl:when test="starts-with(@xlink:href,'#')">
+ <xsl:attribute name="src"><xsl:value-of select="substring-after(@xlink:href,'#')"/></xsl:attribute>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:attribute name="src"><xsl:value-of select="@xlink:href"/></xsl:attribute>
+ </xsl:otherwise>
+ </xsl:choose>
+ </img>
+ </div>
+ </xsl:template>
+ <xsl:template match="title">
+ <xsl:choose>
+ <xsl:when test="@deepness > 5"><h6><a name="@number"></a><xsl:apply-templates/></h6></xsl:when>
+ <xsl:otherwise><xsl:element name="h{@deepness+1}"><a name="@number"></a><xsl:apply-templates/></xsl:element></xsl:otherwise>
+ </xsl:choose>
+
+ </xsl:template>
+ <xsl:template name="for">
+ <xsl:param name="i" select="0"/>
+ <xsl:param name="n" select="$TotalPages"/>
+ <xsl:if test="$i <= $n">
+ <xsl:choose>
+ <xsl:when test="$i = $PageN">
+ <strong>
+ <xsl:choose>
+ <xsl:when test="$i != 0"><xsl:value-of select="$i"/></xsl:when>
+ <xsl:otherwise>Содержание</xsl:otherwise>
+ </xsl:choose>
+ </strong>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:element name="a">
+ <xsl:attribute name="href"><xsl:value-of select="$FileName"/>_<xsl:value-of select="$i"/>.html</xsl:attribute>
+ <xsl:attribute name="title">Перейти на страницу <xsl:value-of select="$i"/></xsl:attribute>
+ <xsl:choose>
+ <xsl:when test="$i != 0"><xsl:value-of select="$i"/></xsl:when>
+ <xsl:otherwise>Содержание</xsl:otherwise>
+ </xsl:choose>
+ </xsl:element>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:if test="$i < $n">  |  </xsl:if>
+ <xsl:call-template name="for">
+ <xsl:with-param name="i" select="$i + 1"/>
+ <xsl:with-param name="n" select="$n"/>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:template>
+</xsl:stylesheet>
\ No newline at end of file
Added: trunk/fb2-perl-tools/fb2/Convert/Htmls.pm
===================================================================
--- trunk/fb2-perl-tools/fb2/Convert/Htmls.pm (rev 0)
+++ trunk/fb2-perl-tools/fb2/Convert/Htmls.pm 2008-01-27 17:52:52 UTC (rev 55)
@@ -0,0 +1,186 @@
+#!/usr/bin/perl
+package FB2ToManyHTML;
+
+use XML::Parser;
+use XML::LibXSLT;
+use XML::LibXML;
+use strict;
+no warnings;
+
+my $Mute;
+my $SectionSize;
+my $MinSectionSize;
+
+my @BodyParts;
+my $RootAttrs;
+my $BookTitle;
+
+sub Kolbasim{
+ my $FileToParce=shift;
+ my $StyleSheet=shift;
+ my $OutFileName=shift;
+ $SectionSize=shift;
+ $MinSectionSize=shift;
+ $Mute=shift;
+ ($RootAttrs,$BookTitle,@BodyParts)=&SplitBook($FileToParce);
+ return TransformParts($StyleSheet,$OutFileName,$RootAttrs,$BookTitle,@BodyParts);
+}
+
+sub SplitBook{
+ my $FileToParce=shift;
+ my $I;
+ my $CurDeepness=0;
+ my ($CurPart,$InBinary,$InHead);
+ my $Description;
+ my @BodyAsArray;
+ my $PartSize=0;
+ my $PartStarted=1;
+ my $InSectionTitle=0;
+ my $AllowSectionTitle=0;
+ my $CanCutHere=1;
+ my $SectionTitle;
+ my @ContentParts;
+ my $InNotesBody;
+ my $RootAttrs;
+ my $BookTitle;
+ my $InBookTitle;
+ my $SplitParser=new XML::Parser(Handlers => {
+ Start => sub {
+ my $expat=shift;
+ my $elem=shift;
+ my %Params=@_;
+ $I++;
+ print "Working element #$I\r" unless $Mute;
+
+ $InHead = 1 if $elem eq 'description';
+ $InBinary=($elem eq 'description')?1:0;
+ $CurPart='' if $elem=~/\Adescription\Z/;
+ if ($elem eq 'FictionBook'){
+ for (keys(%Params)){
+ $RootAttrs.=" $_=\"".xmlescape($Params{$_})."\"" unless $_ eq 'xmlns';
+ }
+ }
+ $InBookTitle=$elem eq 'book-title'?1:0 ;
+ unless ($elem eq 'section'){
+ if ($elem eq 'title'){
+ $Params{'deepness'}=$InNotesBody?5:$CurDeepness;
+ $Params{'number'}=scalar @BodyAsArray;
+ }
+ $CurPart.="<$elem";
+ for (keys(%Params)){
+ $CurPart.=" $_=\"".xmlescape($Params{$_})."\"";
+ }
+ $CurPart.=">";
+ }else{
+ $CurDeepness++;
+ }
+ $AllowSectionTitle=0 if $elem eq 'poem';
+ $InSectionTitle=1 if ($AllowSectionTitle && $elem eq 'title');
+ if ($elem=~/\A(title|epigraph|annotation|poem|cite)\Z/){
+ $CanCutHere=0;
+ }
+ if ($elem=~/\A(section|body)\Z/){
+# $CurPart='' unless $InNotesBody;
+ $CurPart='' if $elem eq 'body';
+ $PartSize=0 if $elem eq 'body';
+ $PartStarted=1;
+ $AllowSectionTitle=1;
+ $SectionTitle='';
+ $InNotesBody=1 if ($elem eq 'body' && $Params{'name'}=~/\Anotes\Z/i);
+ }
+ },
+ Char => sub {
+ $PartSize+=length($_[1]);
+ $CurPart.=xmlescape($_[1]) unless $InBinary;
+ $SectionTitle.=xmlescape($_[1]) if $InSectionTitle;
+ $BookTitle.=xmlescape($_[1]) if $InBookTitle;
+ },
+ End => sub {
+ my $elem=$_[1];
+ $CurPart.="</".$_[1].">" unless $elem=~ /(section|body)/;
+ if (((!$InHead && $CanCutHere && $elem eq 'p' && $PartSize>=$SectionSize) ||
+ ($elem eq 'section' && $PartSize>=$MinSectionSize) || $elem eq 'description') && !$InNotesBody || $elem eq 'body') {
+ my %t=(
+ 'parstart'=>$PartStarted,
+ 'partcontent'=>$CurPart,
+ 'level'=>$CurDeepness
+ );
+ push(@BodyAsArray,\%t) unless $CurPart=~/\A\s+\Z/;
+ $CurPart='';
+ $PartSize=0;
+ $PartStarted=0;
+ $InHead=0 if $_[1] eq 'description';
+ }
+ $CurDeepness-- if $_[1] eq 'section';
+ if ($elem=~/\A(title|epigraph|annotation|poem|cite)\Z/){
+ $CanCutHere=1;
+ }
+ $AllowSectionTitle=0 if $elem eq 'section';
+
+ if ($elem eq 'p' && $InSectionTitle && $SectionTitle){
+ my %t=('title'=>$SectionTitle,'N'=>(scalar @BodyAsArray), 'deep'=>$CurDeepness);
+ push (@ContentParts,\%t);
+ $InSectionTitle=0;
+ $SectionTitle='';
+ $AllowSectionTitle=0;
+ }
+ }
+ });
+
+ $SplitParser->parsefile($FileToParce) or die $!;
+ $SplitParser=undef;
+ for (@ContentParts){
+ $BodyAsArray[0]->{'partcontent'}.="<toc-item n=\"".$_->{'N'}."\" deep=\"".$_->{'deep'}."\">".$_->{'title'}."</toc-item>\n";
+ }
+ return ($RootAttrs,$BookTitle,@BodyAsArray);
+}
+
+sub TransformParts{
+ my $StyleSheet=shift;
+ my $OutFileName=shift;
+ my $RootAttrs=shift;
+ my $BookTitle=shift;
+ my @Parts=@_;
+ my $OutFileSHort=$OutFileName;
+ $OutFileSHort=~s/\A(.*[\/\\])?([^\/\\]*)\Z/$2/;
+ for (my $I=0;$I<@Parts;$I++){
+ my $ItemLength=$Parts[$I]->{'title'};
+ print "Generating file ${OutFileName}_$I.html...\n" unless $Mute;
+ my $Result=TransformXML("<part$RootAttrs>".$Parts[$I]->{'partcontent'}."</part>",
+ $StyleSheet,'PageN'=>"'$I'",
+ 'TotalPages'=>'"'.(@Parts-1).'"',
+ 'FileName'=>"'$OutFileSHort'",
+ 'BookTitle'=>"'$BookTitle'");
+ open OUTFILE,">${OutFileName}_$I.html";
+ print OUTFILE $Result;
+ close OUTFILE;
+ }
+ return scalar(@Parts);
+}
+
+sub xmlescape {
+ my %escapes=(
+ '&' => '&',
+ '<' => '<',
+ '>' => '>',
+ '"' => '"',
+ "'" => '''
+ );
+ $b=shift;
+ $_=$b;
+ s/([&<>'"])/$escapes{$1}/gs;
+ $_;
+}
+
+sub TransformXML{
+ my $XML=shift;
+ my $XSL=shift;
+ my $parser = XML::LibXML->new();
+ my $xslt = XML::LibXSLT->new();
+ my $source = $parser->parse_string($XML);
+ my $style_doc = $parser->parse_file($XSL);
+ my $stylesheet = $xslt->parse_stylesheet($style_doc);
+ my $results = $stylesheet->transform($source,@_);
+ $stylesheet->output_string($results);
+}
+1;
\ No newline at end of file
Added: trunk/fb2-perl-tools/fb22htmls
===================================================================
--- trunk/fb2-perl-tools/fb22htmls (rev 0)
+++ trunk/fb2-perl-tools/fb22htmls 2008-01-27 17:52:52 UTC (rev 55)
@@ -0,0 +1,38 @@
+#!/usr/bin/perl
+
+use FB2ToManyHTML;
+
+my $Mute=0;
+my $SectionSize=30000;
+my $MinSectionSize=20000;
+#=============================================================
+if (!$ARGV[2]){print "\nkolbasorezka.pl by GribUser v 0.01\nUsage:\n\nkolbasorezka.pl <inputfile.fb2> <stylesheet.xsl> <outputfile> [-options]
+
+ outputfile name will be used to create new files.
+ outputfile_page#.html files will be created
+
+ Options available
+ -mute Do not print progress messages.
+ -partsize <number> Set part size (default is $SectionSize)
+ -minsize <number> Set minimum part size (default is $MinSectionSize)
+
+";exit 0;}
+#=============================================================
+
+my $FileToParce=$ARGV[0];
+my $StyleSheet=$ARGV[1];
+my $OutFileName=$ARGV[2];
+for (my $I=3;$I<@ARGV;$I++){
+ $Mute=1 if $ARGV[$I] eq '-mute';
+ if ($ARGV[$I] eq '-partsize'){
+ $SectionSize=$ARGV[$I+1] if $ARGV[$I+1];
+ $I++;
+ }
+ if ($ARGV[$I] eq '-minsize'){
+ $MinSectionSize=$ARGV[$I+1] if $ARGV[$I+1];
+ $I++;
+ }
+
+}
+
+FB2ToManyHTML::Kolbasim($FileToParce,$StyleSheet,$OutFileName,$SectionSize,$MinSectionSize,$Mute);
Property changes on: trunk/fb2-perl-tools/fb22htmls
___________________________________________________________________
Name: svn:executable
+ *
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sh...@us...> - 2008-01-27 17:58:48
|
Revision: 56
http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=56&view=rev
Author: shaplov
Date: 2008-01-27 09:58:54 -0800 (Sun, 27 Jan 2008)
Log Message:
-----------
Editing fb22htmls Step1
Modified Paths:
--------------
trunk/fb2-perl-tools/XSL/fb22htmls.xsl
trunk/fb2-perl-tools/fb2/Convert/Htmls.pm
trunk/fb2-perl-tools/fb22htmls
Modified: trunk/fb2-perl-tools/XSL/fb22htmls.xsl
===================================================================
--- trunk/fb2-perl-tools/XSL/fb22htmls.xsl 2008-01-27 17:52:52 UTC (rev 55)
+++ trunk/fb2-perl-tools/XSL/fb22htmls.xsl 2008-01-27 17:58:54 UTC (rev 56)
@@ -1,5 +1,31 @@
+<!-- Copyright (c) 2004 Dmitry Gribov (GribUser)
+ 2008 Nikolay Shaplov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. The name of the author may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fb="http://www.gribuser.ru/xml/fictionbook/2.0">
- <xsl:output method="html" encoding="windows-1251"/>
+ <xsl:output method="html" encoding="utf-8"/>
<xsl:param name="PageN">1</xsl:param>
<xsl:param name="TotalPages">1</xsl:param>
<xsl:param name="BookTitle">NoName</xsl:param>
Modified: trunk/fb2-perl-tools/fb2/Convert/Htmls.pm
===================================================================
--- trunk/fb2-perl-tools/fb2/Convert/Htmls.pm 2008-01-27 17:52:52 UTC (rev 55)
+++ trunk/fb2-perl-tools/fb2/Convert/Htmls.pm 2008-01-27 17:58:54 UTC (rev 56)
@@ -1,186 +1,214 @@
-#!/usr/bin/perl
-package FB2ToManyHTML;
-
-use XML::Parser;
-use XML::LibXSLT;
-use XML::LibXML;
-use strict;
-no warnings;
-
-my $Mute;
-my $SectionSize;
-my $MinSectionSize;
-
-my @BodyParts;
-my $RootAttrs;
-my $BookTitle;
-
-sub Kolbasim{
- my $FileToParce=shift;
- my $StyleSheet=shift;
- my $OutFileName=shift;
- $SectionSize=shift;
- $MinSectionSize=shift;
- $Mute=shift;
- ($RootAttrs,$BookTitle,@BodyParts)=&SplitBook($FileToParce);
- return TransformParts($StyleSheet,$OutFileName,$RootAttrs,$BookTitle,@BodyParts);
-}
-
-sub SplitBook{
- my $FileToParce=shift;
- my $I;
- my $CurDeepness=0;
- my ($CurPart,$InBinary,$InHead);
- my $Description;
- my @BodyAsArray;
- my $PartSize=0;
- my $PartStarted=1;
- my $InSectionTitle=0;
- my $AllowSectionTitle=0;
- my $CanCutHere=1;
- my $SectionTitle;
- my @ContentParts;
- my $InNotesBody;
- my $RootAttrs;
- my $BookTitle;
- my $InBookTitle;
- my $SplitParser=new XML::Parser(Handlers => {
- Start => sub {
- my $expat=shift;
- my $elem=shift;
- my %Params=@_;
- $I++;
- print "Working element #$I\r" unless $Mute;
-
- $InHead = 1 if $elem eq 'description';
- $InBinary=($elem eq 'description')?1:0;
- $CurPart='' if $elem=~/\Adescription\Z/;
- if ($elem eq 'FictionBook'){
- for (keys(%Params)){
- $RootAttrs.=" $_=\"".xmlescape($Params{$_})."\"" unless $_ eq 'xmlns';
- }
- }
- $InBookTitle=$elem eq 'book-title'?1:0 ;
- unless ($elem eq 'section'){
- if ($elem eq 'title'){
- $Params{'deepness'}=$InNotesBody?5:$CurDeepness;
- $Params{'number'}=scalar @BodyAsArray;
- }
- $CurPart.="<$elem";
- for (keys(%Params)){
- $CurPart.=" $_=\"".xmlescape($Params{$_})."\"";
- }
- $CurPart.=">";
- }else{
- $CurDeepness++;
- }
- $AllowSectionTitle=0 if $elem eq 'poem';
- $InSectionTitle=1 if ($AllowSectionTitle && $elem eq 'title');
- if ($elem=~/\A(title|epigraph|annotation|poem|cite)\Z/){
- $CanCutHere=0;
- }
- if ($elem=~/\A(section|body)\Z/){
-# $CurPart='' unless $InNotesBody;
- $CurPart='' if $elem eq 'body';
- $PartSize=0 if $elem eq 'body';
- $PartStarted=1;
- $AllowSectionTitle=1;
- $SectionTitle='';
- $InNotesBody=1 if ($elem eq 'body' && $Params{'name'}=~/\Anotes\Z/i);
- }
- },
- Char => sub {
- $PartSize+=length($_[1]);
- $CurPart.=xmlescape($_[1]) unless $InBinary;
- $SectionTitle.=xmlescape($_[1]) if $InSectionTitle;
- $BookTitle.=xmlescape($_[1]) if $InBookTitle;
- },
- End => sub {
- my $elem=$_[1];
- $CurPart.="</".$_[1].">" unless $elem=~ /(section|body)/;
- if (((!$InHead && $CanCutHere && $elem eq 'p' && $PartSize>=$SectionSize) ||
- ($elem eq 'section' && $PartSize>=$MinSectionSize) || $elem eq 'description') && !$InNotesBody || $elem eq 'body') {
- my %t=(
- 'parstart'=>$PartStarted,
- 'partcontent'=>$CurPart,
- 'level'=>$CurDeepness
- );
- push(@BodyAsArray,\%t) unless $CurPart=~/\A\s+\Z/;
- $CurPart='';
- $PartSize=0;
- $PartStarted=0;
- $InHead=0 if $_[1] eq 'description';
- }
- $CurDeepness-- if $_[1] eq 'section';
- if ($elem=~/\A(title|epigraph|annotation|poem|cite)\Z/){
- $CanCutHere=1;
- }
- $AllowSectionTitle=0 if $elem eq 'section';
-
- if ($elem eq 'p' && $InSectionTitle && $SectionTitle){
- my %t=('title'=>$SectionTitle,'N'=>(scalar @BodyAsArray), 'deep'=>$CurDeepness);
- push (@ContentParts,\%t);
- $InSectionTitle=0;
- $SectionTitle='';
- $AllowSectionTitle=0;
- }
- }
- });
-
- $SplitParser->parsefile($FileToParce) or die $!;
- $SplitParser=undef;
- for (@ContentParts){
- $BodyAsArray[0]->{'partcontent'}.="<toc-item n=\"".$_->{'N'}."\" deep=\"".$_->{'deep'}."\">".$_->{'title'}."</toc-item>\n";
- }
- return ($RootAttrs,$BookTitle,@BodyAsArray);
-}
-
-sub TransformParts{
- my $StyleSheet=shift;
- my $OutFileName=shift;
- my $RootAttrs=shift;
- my $BookTitle=shift;
- my @Parts=@_;
- my $OutFileSHort=$OutFileName;
- $OutFileSHort=~s/\A(.*[\/\\])?([^\/\\]*)\Z/$2/;
- for (my $I=0;$I<@Parts;$I++){
- my $ItemLength=$Parts[$I]->{'title'};
- print "Generating file ${OutFileName}_$I.html...\n" unless $Mute;
- my $Result=TransformXML("<part$RootAttrs>".$Parts[$I]->{'partcontent'}."</part>",
- $StyleSheet,'PageN'=>"'$I'",
- 'TotalPages'=>'"'.(@Parts-1).'"',
- 'FileName'=>"'$OutFileSHort'",
- 'BookTitle'=>"'$BookTitle'");
- open OUTFILE,">${OutFileName}_$I.html";
- print OUTFILE $Result;
- close OUTFILE;
- }
- return scalar(@Parts);
-}
-
-sub xmlescape {
- my %escapes=(
- '&' => '&',
- '<' => '<',
- '>' => '>',
- '"' => '"',
- "'" => '''
- );
- $b=shift;
- $_=$b;
- s/([&<>'"])/$escapes{$1}/gs;
- $_;
-}
-
-sub TransformXML{
- my $XML=shift;
- my $XSL=shift;
- my $parser = XML::LibXML->new();
- my $xslt = XML::LibXSLT->new();
- my $source = $parser->parse_string($XML);
- my $style_doc = $parser->parse_file($XSL);
- my $stylesheet = $xslt->parse_stylesheet($style_doc);
- my $results = $stylesheet->transform($source,@_);
- $stylesheet->output_string($results);
-}
+#!/usr/bin/perl
+
+# Copyright (c) 2004 Dmitry Gribov (GribUser)
+# 2008 Nikolay Shaplov
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. The name of the author may not be used to endorse or promote products
+# derived from this software without specific prior written permission.
+
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+package fb2::Convert::Htmls;
+
+use XML::Parser;
+use XML::LibXSLT;
+use XML::LibXML;
+use strict;
+no warnings;
+
+my $Mute;
+my $SectionSize;
+my $MinSectionSize;
+
+my @BodyParts;
+my $RootAttrs;
+my $BookTitle;
+
+sub Kolbasim{
+ my $FileToParce=shift;
+ my $StyleSheet=shift;
+ my $OutFileName=shift;
+ $SectionSize=shift;
+ $MinSectionSize=shift;
+ $Mute=shift;
+ ($RootAttrs,$BookTitle,@BodyParts)=&SplitBook($FileToParce);
+ return TransformParts($StyleSheet,$OutFileName,$RootAttrs,$BookTitle,@BodyParts);
+}
+
+sub SplitBook{
+ my $FileToParce=shift;
+ my $I;
+ my $CurDeepness=0;
+ my ($CurPart,$InBinary,$InHead);
+ my $Description;
+ my @BodyAsArray;
+ my $PartSize=0;
+ my $PartStarted=1;
+ my $InSectionTitle=0;
+ my $AllowSectionTitle=0;
+ my $CanCutHere=1;
+ my $SectionTitle;
+ my @ContentParts;
+ my $InNotesBody;
+ my $RootAttrs;
+ my $BookTitle;
+ my $InBookTitle;
+ my $SplitParser=new XML::Parser(Handlers => {
+ Start => sub {
+ my $expat=shift;
+ my $elem=shift;
+ my %Params=@_;
+ $I++;
+ print "Working element #$I\r" unless $Mute;
+
+ $InHead = 1 if $elem eq 'description';
+ $InBinary=($elem eq 'description')?1:0;
+ $CurPart='' if $elem=~/\Adescription\Z/;
+ if ($elem eq 'FictionBook'){
+ for (keys(%Params)){
+ $RootAttrs.=" $_=\"".xmlescape($Params{$_})."\"" unless $_ eq 'xmlns';
+ }
+ }
+ $InBookTitle=$elem eq 'book-title'?1:0 ;
+ unless ($elem eq 'section'){
+ if ($elem eq 'title'){
+ $Params{'deepness'}=$InNotesBody?5:$CurDeepness;
+ $Params{'number'}=scalar @BodyAsArray;
+ }
+ $CurPart.="<$elem";
+ for (keys(%Params)){
+ $CurPart.=" $_=\"".xmlescape($Params{$_})."\"";
+ }
+ $CurPart.=">";
+ }else{
+ $CurDeepness++;
+ }
+ $AllowSectionTitle=0 if $elem eq 'poem';
+ $InSectionTitle=1 if ($AllowSectionTitle && $elem eq 'title');
+ if ($elem=~/\A(title|epigraph|annotation|poem|cite)\Z/){
+ $CanCutHere=0;
+ }
+ if ($elem=~/\A(section|body)\Z/){
+# $CurPart='' unless $InNotesBody;
+ $CurPart='' if $elem eq 'body';
+ $PartSize=0 if $elem eq 'body';
+ $PartStarted=1;
+ $AllowSectionTitle=1;
+ $SectionTitle='';
+ $InNotesBody=1 if ($elem eq 'body' && $Params{'name'}=~/\Anotes\Z/i);
+ }
+ },
+ Char => sub {
+ $PartSize+=length($_[1]);
+ $CurPart.=xmlescape($_[1]) unless $InBinary;
+ $SectionTitle.=xmlescape($_[1]) if $InSectionTitle;
+ $BookTitle.=xmlescape($_[1]) if $InBookTitle;
+ },
+ End => sub {
+ my $elem=$_[1];
+ $CurPart.="</".$_[1].">" unless $elem=~ /(section|body)/;
+ if (((!$InHead && $CanCutHere && $elem eq 'p' && $PartSize>=$SectionSize) ||
+ ($elem eq 'section' && $PartSize>=$MinSectionSize) || $elem eq 'description') && !$InNotesBody || $elem eq 'body') {
+ my %t=(
+ 'parstart'=>$PartStarted,
+ 'partcontent'=>$CurPart,
+ 'level'=>$CurDeepness
+ );
+ push(@BodyAsArray,\%t) unless $CurPart=~/\A\s+\Z/;
+ $CurPart='';
+ $PartSize=0;
+ $PartStarted=0;
+ $InHead=0 if $_[1] eq 'description';
+ }
+ $CurDeepness-- if $_[1] eq 'section';
+ if ($elem=~/\A(title|epigraph|annotation|poem|cite)\Z/){
+ $CanCutHere=1;
+ }
+ $AllowSectionTitle=0 if $elem eq 'section';
+
+ if ($elem eq 'p' && $InSectionTitle && $SectionTitle){
+ my %t=('title'=>$SectionTitle,'N'=>(scalar @BodyAsArray), 'deep'=>$CurDeepness);
+ push (@ContentParts,\%t);
+ $InSectionTitle=0;
+ $SectionTitle='';
+ $AllowSectionTitle=0;
+ }
+ }
+ });
+
+ $SplitParser->parsefile($FileToParce) or die $!;
+ $SplitParser=undef;
+ for (@ContentParts){
+ $BodyAsArray[0]->{'partcontent'}.="<toc-item n=\"".$_->{'N'}."\" deep=\"".$_->{'deep'}."\">".$_->{'title'}."</toc-item>\n";
+ }
+ return ($RootAttrs,$BookTitle,@BodyAsArray);
+}
+
+sub TransformParts{
+ my $StyleSheet=shift;
+ my $OutFileName=shift;
+ my $RootAttrs=shift;
+ my $BookTitle=shift;
+ my @Parts=@_;
+ my $OutFileSHort=$OutFileName;
+ $OutFileSHort=~s/\A(.*[\/\\])?([^\/\\]*)\Z/$2/;
+ for (my $I=0;$I<@Parts;$I++){
+ my $ItemLength=$Parts[$I]->{'title'};
+ print "Generating file ${OutFileName}_$I.html...\n" unless $Mute;
+ my $Result=TransformXML("<part$RootAttrs>".$Parts[$I]->{'partcontent'}."</part>",
+ $StyleSheet,'PageN'=>"'$I'",
+ 'TotalPages'=>'"'.(@Parts-1).'"',
+ 'FileName'=>"'$OutFileSHort'",
+ 'BookTitle'=>"'$BookTitle'");
+ open OUTFILE,">${OutFileName}_$I.html";
+ print OUTFILE $Result;
+ close OUTFILE;
+ }
+ return scalar(@Parts);
+}
+
+sub xmlescape {
+ my %escapes=(
+ '&' => '&',
+ '<' => '<',
+ '>' => '>',
+ '"' => '"',
+ "'" => '''
+ );
+ $b=shift;
+ $_=$b;
+ s/([&<>'"])/$escapes{$1}/gs; #'
+ $_;
+}
+
+sub TransformXML{
+ my $XML=shift;
+ my $XSL=shift;
+ my $parser = XML::LibXML->new();
+ my $xslt = XML::LibXSLT->new();
+ my $source = $parser->parse_string($XML);
+ my $style_doc = $parser->parse_file($XSL);
+ my $stylesheet = $xslt->parse_stylesheet($style_doc);
+ my $results = $stylesheet->transform($source,@_);
+ $stylesheet->output_string($results);
+}
1;
\ No newline at end of file
Modified: trunk/fb2-perl-tools/fb22htmls
===================================================================
--- trunk/fb2-perl-tools/fb22htmls 2008-01-27 17:52:52 UTC (rev 55)
+++ trunk/fb2-perl-tools/fb22htmls 2008-01-27 17:58:54 UTC (rev 56)
@@ -1,12 +1,44 @@
#!/usr/bin/perl
-use FB2ToManyHTML;
+# Copyright (c) 2004 Dmitry Gribov (GribUser),
+# 2008 Nikolay Shaplov
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. The name of the author may not be used to endorse or promote products
+# derived from this software without specific prior written permission.
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+use fb2::Convert::Htmls;
+use strict;
+
+my $xsl_file=$ENV{FB2_PERL_TOOLS};
+$xsl_file.="/" if $xsl_file && $xsl_file =~ /[^\/]$/;
+$xsl_file.="XSL/fb22htmls.xsl";
+
my $Mute=0;
my $SectionSize=30000;
my $MinSectionSize=20000;
#=============================================================
-if (!$ARGV[2]){print "\nkolbasorezka.pl by GribUser v 0.01\nUsage:\n\nkolbasorezka.pl <inputfile.fb2> <stylesheet.xsl> <outputfile> [-options]
+if (!$ARGV[1]){print "\nkolbasorezka.pl by GribUser v 0.01\nUsage:\n\nkolbasorezka.pl <inputfile.fb2> <outputfile> [-options]
outputfile name will be used to create new files.
outputfile_page#.html files will be created
@@ -20,9 +52,8 @@
#=============================================================
my $FileToParce=$ARGV[0];
-my $StyleSheet=$ARGV[1];
-my $OutFileName=$ARGV[2];
-for (my $I=3;$I<@ARGV;$I++){
+my $OutFileName=$ARGV[1];
+for (my $I=2;$I<@ARGV;$I++){
$Mute=1 if $ARGV[$I] eq '-mute';
if ($ARGV[$I] eq '-partsize'){
$SectionSize=$ARGV[$I+1] if $ARGV[$I+1];
@@ -35,4 +66,4 @@
}
-FB2ToManyHTML::Kolbasim($FileToParce,$StyleSheet,$OutFileName,$SectionSize,$MinSectionSize,$Mute);
+fb2::Convert::Htmls::Kolbasim($FileToParce,$xsl_file,$OutFileName,$SectionSize,$MinSectionSize,$Mute);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|