我使用TEI简单,并希望添加编号的标题以及TOC行。我理解如何构建它,但无法在书的各个部分(front、body、back)达到预期的结果。它总是从根部重新开始。我的代码分为两个级别(其余部分我也是这样做的):
<xsl:template match="tei:div[@n='1']/tei:head" mode="toc">
<fo:block font-size="12pt">
<xsl:number format="1. " count="tei:div[@n='1']" level="multiple"/>
<xsl:apply-templates/>
</fo:block>
</xsl:template>
<xsl:template match="tei:div[@n='2']/tei:head" mode="toc">
<fo:block font-size="12pt">
<xsl:number format="1.1. " count="tei:div[@n='1']|tei:div[@n='2']" level="multiple"/>
<xsl:apply-templates/>
</fo:block>
</xsl:template>显然,我用n属性标记任何div。我为文件的整个text部分应用了模板。结果如下:
[Front]
1. First
1.1. First of First
[Body]
1. Second精确的XPaths是:
TEI/text/front/div[@n="1"]/head
TEI/text/body/div[@n="1"]/head
TEI/text/back/div[@n="1"]/head…而且,显然:
TEI/text/front/div[@n="1"]/div[@n="2"]/head
TEI/text/body/div[@n="1"]/div[@n="2"]/head
TEI/text/back/div[@n="1"]/div[@n="2"]/head更新
我已经决定要更严格的书结构了。通常,这是不常见的数字正面和背面的物质。现在,我正在使用这个,它工作正常(我想它可以把所有的主要部分混合在一起,但这种方式对我来说更合理。我用了8个等级。)然而,我不知道是否有另一种更明智的方法来做到这一点。随着级别的增加,代码看起来有点笨拙。
<xsl:template match="tei:div[@n='1']/tei:head[ancestor::tei:front and ancestor::tei:back]" mode="toc">
<xsl:variable name="level" select="count(ancestor-or-self::tei:div)"/>
<fo:inline>
<xsl:apply-templates/>
</fo:inline>
</xsl:template>
<xsl:template match="tei:div[@n='1']/tei:head[ancestor::tei:body]" mode="toc">
<xsl:variable name="level" select="count(ancestor-or-self::tei:div)"/>
<fo:inline>
<xsl:number format="1. " count="tei:div[@n='1'][ancestor::tei:body]" level="multiple"/>
<xsl:apply-templates/>
</fo:inline>
</xsl:template>
<xsl:template match="tei:div[@n='2']/tei:head[ancestor::tei:body]" mode="toc">
<xsl:variable name="level" select="count(ancestor-or-self::tei:div)"/>
<fo:inline>
<xsl:number format="1.1. " count="tei:div[@n='1'][ancestor::tei:body]|tei:div[@n='2'][ancestor::tei: body]" level="multiple"/>
<xsl:apply-templates/>
</fo:inline>
</xsl:template>发布于 2015-12-16 11:18:33
这是一个简短的样本,如果你使用。
<xsl:template match="tei:div[@n='1']/tei:head" mode="toc">
<fo:block font-size="12pt">
<xsl:number format="1. " value="count(preceding::div[@n = 1]) + 1"/>
<xsl:apply-templates/>
</fo:block>
</xsl:template>您应该得到主号码为1.,2.。对于次要编号,我不确定您是否想要跨不同部分的序列,或者是否要将计数限制在每个部分,对于第一个选项使用。
<xsl:template match="tei:div[@n='2']/tei:head" mode="toc">
<fo:block font-size="12pt">
<xsl:number format="1.1 " value="count(preceding::div[@n = 1]) + 1, count(preceding::div[@n = 2]) + 1"/>
<xsl:apply-templates/>
</fo:block>
</xsl:template>第二次
<xsl:template match="tei:div[@n='2']/tei:head" mode="toc">
<fo:block font-size="12pt">
<xsl:number format="1.1 " value="count(preceding::div[@n = 1]) + 1, count(preceding-sibling::div[@n = 2]) + 1"/>
<xsl:apply-templates/>
</fo:block>
</xsl:template>未经测试,但应该给你一个想法。
另一种选择是使用level="any生成主号码,用level="single"生成第二个数字。
https://stackoverflow.com/questions/34309005
复制相似问题