FB2: output a basic book description.
authorMichał Górny <mgorny@gentoo.org>
Sat, 12 May 2012 21:03:44 +0000 (23:03 +0200)
committerMichał Górny <mgorny@gentoo.org>
Sat, 12 May 2012 21:03:44 +0000 (23:03 +0200)
librarian/fb2/description.xslt [new file with mode: 0644]
librarian/fb2/fb2.xslt

diff --git a/librarian/fb2/description.xslt b/librarian/fb2/description.xslt
new file mode 100644 (file)
index 0000000..312df2d
--- /dev/null
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+       This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
+       Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+
+-->
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+       xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+       xmlns:dc="http://purl.org/dc/elements/1.1/"
+       xmlns="http://www.gribuser.ru/xml/fictionbook/2.0">
+
+       <!-- description parsing -->
+       <xsl:template match="rdf:Description" mode="outer">
+               <description>
+                       <!-- need to keep ordering here... -->
+
+                       <title-info>
+                               <!-- obligatory: genre, author, book-title, lang -->
+
+                               <!-- XXX -->
+                               <genre>literature</genre> 
+                               <xsl:apply-templates mode="description"
+                                       select="dc:creator"/>
+                               <xsl:apply-templates mode="description"
+                                       select="dc:title"/>
+                               <xsl:apply-templates mode="description"
+                                       select="dc:date.pd"/>
+                               <xsl:apply-templates mode="description"
+                                       select="dc:language"/>
+                       </title-info>
+                       <document-info>
+                               <!-- obligatory: author, date, id, version -->
+
+                               <xsl:apply-templates mode="description"
+                                       select="dc:contributor.editor"/>
+                               <xsl:apply-templates mode="description"
+                                       select="dc:contributor.technical_editor"/>
+                               <program-used>book2fb2</program-used>
+                               <!-- maybe today's date instead? -->
+                               <xsl:apply-templates mode="description"
+                                       select="dc:date"/>
+                               <xsl:apply-templates mode="description"
+                                       select="dc:identifier.url"/>
+                               <!-- XXX -->
+                               <version>0</version>
+                       </document-info>
+                       <publish-info>
+                               <xsl:apply-templates mode="description"
+                                       select="dc:publisher"/>
+                       </publish-info>
+               </description>
+       </xsl:template>
+
+       <xsl:template mode="description"
+                       match="dc:creator|dc:contributor.editor|dc:contributor.technical_editor">
+               <!-- last name, first name -->
+               <xsl:variable name="last"
+                       select="normalize-space(substring-before(., ','))"/>
+               <xsl:variable name="first"
+                       select="normalize-space(substring-after(., ','))"/>
+
+               <author>
+                       <first-name><xsl:value-of select="$first"/></first-name>
+                       <last-name><xsl:value-of select="$last"/></last-name>
+               </author>
+       </xsl:template>
+       <xsl:template mode="description" match="dc:title">
+               <book-title><xsl:value-of select="."/></book-title>
+       </xsl:template>
+       <xsl:template mode="description" match="dc:language">
+               <lang><xsl:value-of select="."/></lang>
+       </xsl:template>
+       <xsl:template mode="description" match="dc:date.pd|dc:date">
+               <date><xsl:value-of select="."/></date>
+       </xsl:template>
+       <xsl:template mode="description" match="dc:publisher">
+               <publisher><xsl:value-of select="."/></publisher>
+       </xsl:template>
+       <xsl:template mode="description" match="dc:identifier.url">
+               <id><xsl:value-of select="."/></id>
+       </xsl:template>
+</xsl:stylesheet>
index 915bad4..487fdb7 100644 (file)
@@ -7,10 +7,10 @@
 -->
 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:wl="http://wolnelektury.pl/functions"
-       xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns="http://www.gribuser.ru/xml/fictionbook/2.0"
        xmlns:l="http://www.w3.org/1999/xlink">
 
+       <xsl:include href="description.xslt"/>
        <xsl:include href="footnotes.xslt"/>
        <xsl:include href="inline.xslt"/>
        <xsl:include href="paragraphs.xslt"/>
                </FictionBook>
        </xsl:template>
 
-       <xsl:template match="dc:*" mode="outer">
-       </xsl:template>
-
        <!-- we can't handle lyrics nicely yet -->
-       <xsl:template match="powiesc|opowiadanie" mode="outer">
+       <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp" mode="outer">
                <body> <!-- main body for main book flow -->
                        <xsl:if test="autor_utworu or nazwa_utworu">
                                <title>