首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XSL-FO列表标签宽度

XSL-FO列表标签宽度
EN

Stack Overflow用户
提问于 2015-10-08 01:19:04
回答 2查看 1.2K关注 0票数 0

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

代码语言:javascript
复制
  <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>

但是,如果我有一个罗马列表,我必须使临时距离开始更大,以说明标签的大小,这可能是许多字母的长度

代码语言:javascript
复制
  <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代码来考虑标签类型和列表项数量的不同组合,以动态分配临时开始之间的距离?

EN

回答 2

Stack Overflow用户

发布于 2016-04-26 17:22:59

我也一直在为此而苦苦挣扎。对我来说,最简单的解决方案是使用所有可能性的条件。我只需要一件事就是计算前面的兄弟姐妹。以下是我在属性集中使用的内容:

用于XSLT1.0的

代码语言:javascript
复制
<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>

适用于XSLT2.0及更高版本

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

当然,对于包含数百个项目的长列表和嵌套列表,也有必要使用相同的方法。

票数 1
EN

Stack Overflow用户

发布于 2015-10-08 06:55:23

如果您不想像@kevin-brown建议的那样使用表格--例如,您正在使用FOP,它不进行自动表格布局--您可以使用Print and Page layout Community Group的扩展函数在XSLT转换期间获取区域树。

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32998543

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档