XSL:无法截断列上的文本

XSL: can not truncate text on column

我正在使用 XSL 来获得 XML 样式。 xsl 定义了一个有两列的 table。我需要做的是截断列末尾的文本。

我使用函数 substring 将文本截断为固定数量的字符,但由于不同字符的大小不同,结果非常难看

这是我想要的示例:

假设table中必须包含的字符串是:

"short text"

"some text here"

"this is a very long text"

"this is a very very long text"

|     COLUMN 1       | COLUMN 2 |
|--------------------|----------|
|some text           | column 2 |
|some text here      | column 2 |
|this is a very long | column 2 |
|this is a very very | column 2 |

是否存在 xsl 函数根据字符串在列中填充的大小而不是字符数来截断字符串?

提前致谢。

您在 table 单元格中放置一个足够高(大于一行但小于两行)的块容器,将溢出设置为隐藏:

    <fo:table-cell>
        <fo:block-container overflow="hidden" height="15pt"><fo:block>this is a very, very, very long text here</fo:block></fo:block-container>
    </fo:table-cell>

请注意,这会在单词边界处截断。如果您想在任意位置切断,那么您可以在单词中的每个字母之间插入零宽度的分隔符。上面的 table 显示它在下面的最后 "very" 处被切碎: