XSL-FO 中的章节编号 [英] Chapter numbering in XSL-FO

查看:35
本文介绍了XSL-FO 中的章节编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下形式的 xml:第1章第 1.1 章
第 1.1.1 章第 1.2 章

I have xml of the form: Chapter 1 Chapter 1.1
Chapter 1.1.1 Chapter 1.2

<CHAPTER>
 <LONG-NAME>Chapter 2</LONG-NAME>
  <CHAPTER>
 <LONG-NAME>Chapter 2.1</LONG-NAME>
 </CHAPTER>
 <CHAPTER>
 <LONG-NAME>Chapter 2.2</LONG-NAME>
 </CHAPTER>
</CHAPTER>
</REPORT-BODY>

一章内可以有任意数量的章节.如何编写 xsl-fo 以获取输出 pdf 如下:

there can be any number of chapters inside one chapter. how to write xsl-fo to get the out pdf as below:

1. Chapter 1
1.1 chapter 1.1
1.1.1 Chapter 1.1.1
1.2 Chapter 1.2

2.Chapter 2
2.1 Chapter 2.1
2.2 Chapter 2.2

我尝试使用:

 <xsl:template
    match="CHAPTER/LONG-NAME">
   <fo:block
        color="#374B80"
        font-size="12px"
        font-family="Helvetica"
        font-weight="bold"
        padding-top="3px"
        padding-bottom="3px">
<xsl:if test="ancestor::REPORT-BODY">
    <xsl:variable name="chapNum">
    <xsl:number from="CHAPTER" count="LONG-NAME" format="1 " level="any"/>
    </xsl:variable>
   <xsl:value-of select="$chapNum"/>    
   </xsl:if>
<xsl:if test="ancestor::CHAPTER">
<xsl:variable name="chapNumber">
<xsl:text>.</xsl:text>
  <xsl:number from="CHAPTER/CHAPTER" count="LONG-NAME" format="1. " level="any"/>
  </xsl:variable>   
  <xsl:value-of select="$chapNumber"/>  
   </xsl:if>      
   <xsl:apply-templates/>
   </fo:block>
   </xsl:template>

但我无法实现所需的编号.

but i am not able to achieve the required numbering.

推荐答案

尝试使用 xsl:number 像这样:

<xsl:number format="1. " count="CHAPTER" level="multiple"/>

你应该可以用这个替换你的模板:

You should be able to replace your template with this one:

<xsl:template match="CHAPTER/LONG-NAME">
    <fo:block
        color="#374B80"
        font-size="12px"
        font-family="Helvetica"
        font-weight="bold"
        padding-top="3px"
        padding-bottom="3px">
        <xsl:number format="1. " count="CHAPTER" level="multiple"/>     
        <xsl:value-of select="."/>
    </fo:block>
</xsl:template>

这篇关于XSL-FO 中的章节编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆