基于Apache XSL-FO实现圣经书籍导向的自动化目录生成技术问询
Hey there! Let's get your automated biblical table of contents sorted out—manual work is never fun, especially with something that needs precision like this. First, I spotted a couple of simple typos in your existing code that are probably blocking progress, then we can adjust the structure to group entries by biblical book as you need.
First: Fix the Typos
You've got a couple of misspellings of select as selcet—those will break your templates right away. Let's correct those first:
- In the
<xsl:for-each>inside theKapiteltemplate, changeselcet="Abschnitt"toselect="Abschnitt" - In the
IVZ-Eintragtemplate, changeselcet="Titel"toselect="Titel"
Second: Add Biblical Book Grouping
Assuming your XML structure has a parent element for each biblical book (let's say <Buch> for example—adjust the node name if yours is different like <Book>), here's how to restructure the XSLT to group your TOC by book:
<!-- Match each biblical book to create a top-level TOC section --> <xsl:template match="Buch"> <fo:block font-size="14pt" font-weight="bold" margin-top="1em"> <xsl:value-of select="Titel"/> </fo:block> <!-- Apply templates for chapters under this book --> <xsl:apply-templates select="Kapitel"/> </xsl:template> <xsl:template match="Kapitel"> <fo:block margin-left="1em"> <xsl:apply-templates select="Titel" mode="Kap-Titel"/> </fo:block> <!-- Fixed the typo here: selcet → select --> <xsl:for-each select="Abschnitt"> <xsl:call-template name="IVZ-Eintrag"/> </xsl:for-each> <xsl:apply-templates/> </xsl:template> <xsl:template match="Kapitel/Titel"/> <!-- Fixed the typo here: selcet → select --> <xsl:template name="IVZ-Eintrag"> <fo:block text-align-last="justify" margin-left="2em"> <xsl:apply-templates select="Titel" mode="IVZ-Titel"/> <fo:leader/> <fo:page-number-citation ref-id="{generate-id()}"/> </fo:block> </xsl:template> <xsl:template match="Abschnitt"> <fo:block id="{generate-id()}"> <xsl:apply-templates/> </fo:block> </xsl:template>
How This Works
- The
Buchtemplate creates a bold, larger heading for each biblical book, making your TOC grouped clearly. - We've fixed the two
selcettypos so the loops and template applications actually work. - The indentation (
margin-left) helps visually distinguish books → chapters → sections in the TOC, making it easier to read. - The
generate-id()still correctly links each section to its page number, so the citation works as intended.
If your XML uses a different name for the book element (like <Book> instead of <Buch>), just update the match="Buch" line to match your actual node name.
内容的提问来源于stack exchange,提问作者Andrej90

