问题
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>
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
i tried using:
<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.
回答1:
Try using xsl:number
like this:
<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>
来源:https://stackoverflow.com/questions/16034774/chapter-numbering-in-xsl-fo