2015-10-07 28 views
0

有没有办法让列表标签的宽度更具动态性?例如...如果我有一个简单的阿拉伯语列表(只有几个项目),我并不需要太多的空间来放置标签,所以我可以将我的临时距离设置为一个很小的数字。XSL-FO列表标签宽度

<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以解决标签类型和列表项数量的不同组合以便动态分配临时起点间距?

+0

改为使用表格。如果你的fo处理器支持动态设置列宽。 –

回答

0

如果您不想使用表格作为@ kevin-brown建议的 - 例如,您使用的是FOP,它不会执行自动表格布局 - 您可以使用Print and Page Layout Community Group扩展函数用于在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.

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

0

我一直在为此苦苦挣扎。最简单的解决方案是我为所有可能性使用条件。我只需要计算一下前面的兄弟姐妹。这里我在属性中使用什么套:

为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> 

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