XSL-FO列表标签宽度

时间:2015-10-07 17:19:04

标签: xslt xsl-fo

有没有办法让列表标签的宽度更加动态?例如...如果我有一个简单的阿拉伯语列表(只有几个项目),我真的不需要太多的标签空间,所以我可以设置我的临时距离开始是一个小数字。 / p>

  <fo:list-block provisional-label-separation="1mm" provisional-distance-between-starts="3.5mm">
     <fo:list-item>
        <fo:list-item-label end-indent="label-end()">
           <fo:block font-size="9pt">1.</fo:block>
        </fo:list-item-label>
        <fo:list-item-body start-indent="body-start()">
           <fo:block font-size="9pt">Text of the list item</fo:block>
        </fo:list-item-body>
     </fo:list-item>
     <fo:list-item>
        <fo:list-item-label end-indent="label-end()">
           <fo:block font-size="9pt">2.</fo:block>
        </fo:list-item-label>
        <fo:list-item-body start-indent="body-start()">
           <fo:block font-size="9pt">Text of the list item</fo:block>
        </fo:list-item-body>
     </fo:list-item>
  </fo:list-block>

但是,如果我有一个罗马列表,我必须使开始之间的临时距离大得多,以考虑标签的大小,这可能是很多字母长

  <fo:list-block provisional-label-separation="1mm" provisional-distance-between-starts="6mm">
     <fo:list-item>
        <fo:list-item-label end-indent="label-end()">
           <fo:block font-size="9pt">xii.</fo:block>
        </fo:list-item-label>
        <fo:list-item-body start-indent="body-start()">
           <fo:block font-size="9pt">Text of the list item</fo:block>
        </fo:list-item-body>
     </fo:list-item>
     <fo:list-item>
        <fo:list-item-label end-indent="label-end()">
           <fo:block font-size="9pt">xiii.</fo:block>
        </fo:list-item-label>
        <fo:list-item-body start-indent="body-start()">
           <fo:block font-size="9pt">Text of the list item</fo:block>
        </fo:list-item-body>
     </fo:list-item>
  </fo:list-block>

我希望标签只占用所需的空间,具体取决于标签类型和商品数量。在FO中是否存在动态解决方案,或者我是否必须编写我的XSLT以考虑标签类型和列表项数量的不同组合以动态分配临时间距 - 开始之间的距离?

2 个答案:

答案 0 :(得分:1)

我也一直在努力解决这个问题。最简单的解决方案是让我使用所有可能性的条件。我需要的只有一件事是计算前面的兄弟姐妹。这是我在属性集中使用的内容:

适用于XSLT 1.0

<xsl:attribute name="start-indent">
    <xsl:choose>
        <!-- Counts *preceding* siblings, hence the 8 and le! -->
        <xsl:when test="count(preceding-sibling::item) &lt;= 8">
            <xsl:text>1em</xsl:text>
        </xsl:when>
        <xsl:otherwise>
            <xsl:text>1.4em</xsl:text>
        </xsl:otherwise>
    </xsl:choose>
</xsl:attribute>

适用于XSLT 2.0及更高版本

<xsl:attribute name="start-indent">
    <xsl:value-of select="if (count(preceding-sibling::item) le 8) then '1em' else '1.4em'"/>
</xsl:attribute>

当然,对于包含数百个项目的长列表以及嵌套列表,必须使用相同的内容。

答案 1 :(得分:0)

如果您不想使用@ kevin-brown建议的表格 - 例如,您使用FOP,而不是自动表格布局 - 您可以使用打印和页面布局社区组的扩展函数,用于在XSLT转换期间获取区域树。

http://www.w3.org/community/ppl/wiki/XSLTExtensions#Example_4_-_List_item_label_width处调整列表项标签宽度的示例:

Two lists with list item label width set to exactly match formatted widths of labels.

2014年Balisage在https://www.w3.org/community/ppl/2015/02/18/getting-an-area-tree-within-your-xslt-transform/的海报中有另一个例子,其中还有一个向下移动列表项主体以避免长列表项标签的示例。