I have a book in fb2 format. I want to print the table of contents, containing names and numbers of "parts", "chapters", "episodes" and so on.
Is there a way I can do this from terminal? There is a similar question, but for epub format.
I know fb2 is an xml format. But is there a tool to extract only TOC? They are inside tags <section>
, <title>
and <subtitle>
.
If there is not, I guess it is possible to make xsl file based on official FB2_to_txt.xsl file. Also maybe ebook-convert could do this?
The book that I am working on has the following structure:
<?xml version="1.0" encoding="utf8"?>
<FictionBook xmlns:l="http://www.w3.org/1999/xlink" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.gribuser.ru/xml/fictionbook/2.0">
<description>
<title-info>
<genre>fiction</genre>
<author>
<first-name>John</first-name>
<last-name>Doe</last-name>
</author>
<book-title>Fiction Book</book-title>
<annotation>
<p>Hello</p>
</annotation>
<keywords>john, doe, fiction</keywords>
<date value="2011-07-18">18.07.2011</date>
<coverpage></coverpage>
<lang>en</lang>
</title-info>
<document-info>
<author>
<first-name></first-name>
<last-name></last-name>
<nickname></nickname>
</author>
<program-used>Fb2 Gem</program-used>
<date value="2011-07-18">18.07.2011</date>
<src-url></src-url>
<src-ocr></src-ocr>
<id></id>
<version>1.0</version>
</document-info>
<publish-info>
</publish-info>
</description>
<body>
<title>
<p>John Doe</p>
<empty-line/>
<p>Fiction Book</p>
</title>
<section>
<title>
<p>Part 1</p>
<p>Some name of Part 1</p>
</title>
<section>
<title>
<p>Chapter 1</p>
<p>Some name of Chapter 1</p>
</title>
<subtitle>Episode 1</subtitle>
<p>Line one of the first episode</p>
<p>Line two of the first episode</p>
<p>Line three of the first episode</p>
<subtitle>Episode 2</subtitle>
<p>Line one of the second episode</p>
<p>Line two of the second episode</p>
<p>Line three of the second episode</p>
</section>
</section>
<section>
<title>
<p>Part 2</p>
<p>Some name of Part 2</p>
</title>
<section>
<title>
<p>Chapter 3</p>
<p>Some name of Chapter 3</p>
</title>
<subtitle>Episode 3</subtitle>
<p>Line one of the third episode</p>
<p>Line two of the third episode</p>
<p>Line three of the third episode</p>
<subtitle>Episode 4</subtitle>
<p>Line one of the fourth episode</p>
<p>Line two of the fourth episode</p>
<p>Line three of the fourth episode</p>
</section>
</section>
</body>
</FictionBook>
I want to get the following on the output:
Part 1
Some name of Part 1
Chapter 1
Some name of Chapter 1
Episode 1
Episode 2
Part 2
Some name of Part 2
Chapter 3
Some name of Chapter 3
Episode 3
Episode 4
_
? – Gilles Quénot May 05 '23 at 13:22xmlstarlet
-specific thing. – Kusalananda May 05 '23 at 14:09