List XSL-FO-如何在两个列表块中继续数字?

List XSL-FO-如何在两个列表块中继续数字?,list,xslt,xsl-fo,docbook,List,Xslt,Xsl Fo,Docbook,有人知道如何通过XSL-FO转换实现这一点吗?以下代码中应明确问题的详细信息 输入: <section> <title>Section 1</title> <orderedlist> <listitem><para>item 1.1</para></listitem> <listitem> <para>it

有人知道如何通过XSL-FO转换实现这一点吗?以下代码中应明确问题的详细信息

输入:

<section>
    <title>Section 1</title>
    <orderedlist>
        <listitem><para>item 1.1</para></listitem>
        <listitem>
            <para>item 1.2</para>
            <orderedlist>
                <listitem><para>item a</para></listitem>
                <listitem><para>item b</para></listitem>
            </orderedlist>
        </listitem>
    </orderedlist>
</section>
<section>
    <title>Section 2</title>
    <orderedlist>
        <listitem><para>item 2.1</para></listitem>
        <listitem><para>item 2.2</para></listitem>
    </orderedlist>
</section>
Section 1
1. item 1.1
2. item 1.2
   a. item a
   b. item b

Section 2
3. item 2.1
4. item 2.2
下面是列表的XSL文件:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format">

    <!-- templates for lists - supports numbered and itemized types -->
    <!-- the maximum depth is currently 2 -->
    <xsl:template match="orderedlist">
        <fo:list-block start-indent="0.5cm" space-before="0.2cm"
            provisional-distance-between-starts="0.7cm">
            <xsl:apply-templates />
        </fo:list-block>
    </xsl:template>
    <xsl:template match="orderedlist//orderedlist">
        <fo:list-block start-indent="1.2cm" provisional-distance-between-starts="0.7cm"
            padding-top="-0.2cm" padding-bottom="0.2cm">
            <xsl:apply-templates />
        </fo:list-block>
    </xsl:template>
    <xsl:template match="itemizedlist">
        <fo:list-block start-indent="0.5cm" space-before="0.2cm"
            provisional-distance-between-starts="0.7cm">
            <xsl:apply-templates />
        </fo:list-block>
    </xsl:template>
    <xsl:template match="itemizedlist//itemizedlist">
        <fo:list-block start-indent="1.2cm" provisional-distance-between-starts="0.7cm"
            padding-top="-0.2cm" padding-bottom="0.2cm">
            <xsl:apply-templates />
        </fo:list-block>
    </xsl:template>
    <xsl:template match="orderedlist/listitem">
        <fo:list-item margin-top="0.1cm">
            <fo:list-item-label end-indent="label-end()">
                <fo:block>
                    <xsl:number count="listitem" format="1." />
                </fo:block>
            </fo:list-item-label>
            <fo:list-item-body start-indent="body-start()">
                <fo:block>
                    <xsl:apply-templates />
                </fo:block>
            </fo:list-item-body>
        </fo:list-item>
    </xsl:template>
    <xsl:template match="orderedlist//orderedlist/listitem">
        <fo:list-item>
            <fo:list-item-label end-indent="label-end()">
                <fo:block>
                    <xsl:number count="listitem" format="a." />
                </fo:block>
            </fo:list-item-label>
            <fo:list-item-body start-indent="body-start()">
                <fo:block>
                    <xsl:apply-templates />
                </fo:block>
            </fo:list-item-body>
        </fo:list-item>
    </xsl:template>
    <xsl:template match="itemizedlist/listitem">
        <fo:list-item margin-top="0.1cm">
            <fo:list-item-label end-indent="label-end()">
                <fo:block>&#8226;</fo:block>
            </fo:list-item-label>
            <fo:list-item-body start-indent="body-start()">
                <fo:block>
                    <xsl:apply-templates />
                </fo:block>
            </fo:list-item-body>
        </fo:list-item>
    </xsl:template>
    <xsl:template match="itemizedlist//itemizedlist/listitem">
        <fo:list-item>
            <fo:list-item-label end-indent="label-end()">
                <fo:block>&#8226;</fo:block>
            </fo:list-item-label>
            <fo:list-item-body start-indent="body-start()">
                <fo:block>
                    <xsl:apply-templates />
                </fo:block>
            </fo:list-item-body>
        </fo:list-item>
    </xsl:template>
</xsl:stylesheet>

•
•

您不使用DocBook和样式表有什么特殊原因吗?这会给你很多“免费的”(也许你已经知道了)


在DocBook中,您要求的已经实现。上有一个
continuation
属性,用于指示列表中的编号是否从上一个列表继续。FO输出的DocBook XSL样式表中支持这一点(请查看FO/lists.XSL和common/common.XSL以了解其实现方式)

假设您输入的样本是(添加了部分最上面的元素以使样本格式良好):

例如:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:output indent="yes"/>

    <xsl:template match="sections">
        <fo:block>
            <xsl:apply-templates select="section"/>
        </fo:block>
    </xsl:template>

    <xsl:template match="section">
        <fo:list-block>
            <xsl:apply-templates select="title | orderedlist/listitem"/>
        </fo:list-block>
    </xsl:template>

    <xsl:template match="title">
        <fo:list-item>
            <xsl:value-of select="."/>
        </fo:list-item>
    </xsl:template>

    <xsl:template match="listitem">
        <fo:list-item>
            <xsl:number 
                value="count(
                preceding-sibling::listitem 
                | 
                ../../preceding-sibling::section/orderedlist/listitem) 
                + 1" format="1.&#x20;"/>
        </fo:list-item>
    </xsl:template>
</xsl:stylesheet>

产生:

<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format">
   <fo:list-block>
      <fo:list-item>Section 1</fo:list-item>
      <fo:list-item>1. </fo:list-item>
      <fo:list-item>2. </fo:list-item>
   </fo:list-block>
   <fo:list-block>
      <fo:list-item>Section 2</fo:list-item>
      <fo:list-item>3. </fo:list-item>
      <fo:list-item>4. </fo:list-item>
   </fo:list-block>
</fo:block>

第一节
1.
2.
第二节
3.
4.

您正在使用DocBook吗?您的输入XML看起来像。@mzjn不,我只使用DocBook标记(以防将来使用DocBook),但我使用自己的转换。有什么办法解决这个问题吗?这几乎行得通。问题是我在第一部分中有另一个嵌套的
orderedlist
,第二部分也从嵌套列表中计算listitems。我试图更改级别,但没有任何区别。此外,如果我在下面有另一个orderedlist,则数字将继续。我只想把这两个数字加在一起,剩下的从1开始。现在检查我的答案。如果仍然与您的意图相去甚远,请提供所需输出的更好描述/示例。这太棒了!我稍微调整了一下,效果不错。非常感谢。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:output indent="yes"/>

    <xsl:template match="sections">
        <fo:block>
            <xsl:apply-templates select="section"/>
        </fo:block>
    </xsl:template>

    <xsl:template match="section">
        <fo:list-block>
            <xsl:apply-templates select="title | orderedlist/listitem"/>
        </fo:list-block>
    </xsl:template>

    <xsl:template match="title">
        <fo:list-item>
            <xsl:value-of select="."/>
        </fo:list-item>
    </xsl:template>

    <xsl:template match="listitem">
        <fo:list-item>
            <xsl:number 
                value="count(
                preceding-sibling::listitem 
                | 
                ../../preceding-sibling::section/orderedlist/listitem) 
                + 1" format="1.&#x20;"/>
        </fo:list-item>
    </xsl:template>
</xsl:stylesheet>
<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format">
   <fo:list-block>
      <fo:list-item>Section 1</fo:list-item>
      <fo:list-item>1. </fo:list-item>
      <fo:list-item>2. </fo:list-item>
   </fo:list-block>
   <fo:list-block>
      <fo:list-item>Section 2</fo:list-item>
      <fo:list-item>3. </fo:list-item>
      <fo:list-item>4. </fo:list-item>
   </fo:list-block>
</fo:block>