我的XML输入中有数字列表,并且我能够对齐列表正文(文本内容)以向右对齐,但是数字保持与左对齐。如何使整个列表(包括数字/符号)向右对齐,默认情况下是左对齐。任何帮助或指示都是非常感谢的,谢谢。
当前产出:
Number list below
1. L List 1
2. R list 2
我的预期产出:
Number list below
1. L List 1
2. R list 2
我已经将xml数据简化如下:
<p>Number list below</p>
<ol>
<li style="text-align: right;">L list 1</li>
<li style="text-align: right;">R list 2</li>
</ol>
我的xslt代码如下所示:
<xsl:template match="LI|li">
<fo:list-block>
<xsl:attribute name="text-align">
<!--xsl:value-of select="end"/-->
<xsl:text disable-output-escaping="yes">right</xsl:text>
</xsl:attribute>
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block>
<xsl:variable name="value-fetcher">
<xsl:choose>
<xsl:when test="../@start">
<xsl:number value="count(preceding-sibling::li) + count(preceding-sibling::LI)+ ../@start"/>
</xsl:when>
<xsl:otherwise>
<xsl:number value="count(preceding-sibling::li) + count(preceding-sibling::LI) + 1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:number value="$value-fetcher" format="1."/>
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block>
<xsl:apply-templates select="text()"/>
</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</xsl:template>
发布于 2017-12-12 10:05:59
谢谢你的回复,总是有用的。
通过以下xslt实现对齐:
<xsl:template match="LI|li">
<fo:block margin-left="36pt" text-align="right">
<fo:leader leader-pattern="space" leader-length="-18pt"/>
<fo:inline><xsl:variable name="value-fetcher">
<xsl:choose>
<xsl:when test="../@start">
<xsl:number value="count(preceding-sibling::li) + count(preceding-sibling::LI)+ ../@start"/>
</xsl:when>
<xsl:otherwise>
<xsl:number value="count(preceding-sibling::li) + count(preceding-sibling::LI) + 1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:number value="$value-fetcher" format="1."/>
</fo:inline>
<fo:inline>
<fo:leader leader-pattern="space" leader-length="18pt"/>
<xsl:apply-templates select="text()"/>
</fo:inline>
</fo:block>
</xsl:template>
发布于 2017-12-04 00:07:18
在我看来,一个对齐的、可变宽度的列表并不是fo:list-block设计的那样。
假设您的FO格式化程序实现了fo:table-and-caption,那么您可以创建一个与您想要的表类似的表:
<table-and-caption text-align="right">
<table text-align="left">
<table-body>
<table-row>
<table-cell padding="1pt">
<block>1.</block>
</table-cell>
<table-cell padding="1pt">
<block>L List 1</block>
</table-cell>
</table-row>
</table-body>
<table-body>
<table-row>
<table-cell padding="1pt">
<block>2.</block>
</table-cell>
<table-cell padding="1pt">
<block>R list 2</block>
</table-cell>
</table-row>
</table-body>
</table>
</table-and-caption>在没有fo:table-and-caption的情况下,可以滥用fo:block-container和writing-mode属性:
<block-container writing-mode="rl">
<table text-align="left" writing-mode="lr">也可以使用fo:leader (leader)将fo:inline-container (inline-container)“推”到右侧:
<block>
<leader leader-length.optimum="100%"/><inline-container>
<table>发布于 2017-12-02 11:24:10
模板有几个问题:
provisional-distance-between-starts,它与provisional-label-separation一起决定项目标签的宽度,因此您的宽度为24pt - 6pt =18 6pt。end-indent="label-end()",而且项目主体缺少start-indent="body-start()",因此它们的大小/位置不正确。这一经修订的模板应能发挥作用:
<xsl:template match="LI|li">
<fo:list-block text-align="end" provisional-distance-between-starts="3cm"><!-- set the value you want! -->
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block>
<xsl:variable name="value-fetcher">
<xsl:choose>
<xsl:when test="../@start">
<xsl:number value="count(preceding-sibling::li) + count(preceding-sibling::LI)+ ../@start"/>
</xsl:when>
<xsl:otherwise>
<xsl:number value="count(preceding-sibling::li) + count(preceding-sibling::LI) + 1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:number value="$value-fetcher" format="1."/>
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block>
<xsl:apply-templates select="text()"/>
</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</xsl:template>只是一个小问题:您正在为输入中的每个li元素创建一个li,而您只可以为每个ol或ul创建一个。
由于您不知道预先为标签预留的宽度,但它取决于项目文本本身.好吧,也许你根本不需要使用fo:list-block!
如果项目文本总是只创建一行,则对右对齐的fo:block就足够了:
<xsl:template match="LI|li">
<fo:block text-align="end">
<fo:inline>
<xsl:variable name="value-fetcher">
<xsl:choose>
<xsl:when test="../@start">
<xsl:number value="count(preceding-sibling::li) + count(preceding-sibling::LI)+ ../@start"/>
</xsl:when>
<xsl:otherwise>
<xsl:number value="count(preceding-sibling::li) + count(preceding-sibling::LI) + 1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:number value="$value-fetcher" format="1."/>
</fo:inline>
<fo:inline>
<xsl:apply-templates select="text()"/>
</fo:inline>
</fo:block>
</xsl:template>https://stackoverflow.com/questions/47606454
复制相似问题