In <fo:table-column> what is the difference between the number-columns-spanned vs. number-columns-repeated attributes?

北城余情 提交于 2019-12-14 01:43:21

问题


Actually, using AHFormatter, if I have this:

<fo:table-column column-number="2" number-columns-repeated="2" color="red"/>

Then a table-cell in the 3rd column will have red text if I use from-table-column():

<fo:table-cell color="from-table-column()">

However,

<fo:table-column column-number="2" number-columns-spanned="2" color="red"/>

does not work this way, so maybe the real question is what does the number-columns-spanned attribute of <fo:table-column/> do, if anything?


回答1:


The previously provided answer, copied directly from the W3C XSL-FO 1.1 spec gives a fairly clear explanation of what number-columns-repeated="n" does, namely it's a convenience attribute which has the same effect as if the <fo:table-column/> formatting object had been repeated n times in the result tree. This models the xhtml <col/> tag span attribute.

The comment made in the spec that "this handles HTML's 'colgroup" element" is generally incorrect. <colgroup> can be a container for <col/> tags, and each <col/> element can provide completely different formatting attributes (in addition to spanning one or more columns). This statement is only true when using empty <colgroup> tags (which is permissible, but confusing, since this is equivalent to just using <col> tags and dispensing with <colgroup>'s altogether). The xhtml DTD does not allow <col> and <colgroup> to be siblings. You can use all <col> elements or all <colgroup> elements (which can have <col> children, or use span, but not both), or neither.

The number-columns-spanned attribute acts as an additional <table-cell> identifier. For example, given

<fo:table-column column-number="2" color="green" number-columns-spanned="2"/>

if both these <table-cell>'s are in the second column:

<fo:table-cell color="from-table-column()">
<fo:table-cell number-columns-spanned="2" color="from-table-column()">

only the second table-cell would be rendered with green text.

This allows for separate formatting for table-cells spanning a different number of columns; for example:

<fo:table-column column-number="2" color="red"/>
<fo:table-column column-number="2" background-color="lightgray" color="green" number-columns-spanned="2"/>

would provide the opportunity to use the from-table-column() function to color the text in any single column table-cells in the second column red, while rendering a lightgray background for table-cells extending across the second and third columns with green text.

One point of confusion. The spec has this to say about the from-table-column():

The from-table-column function returns the inherited value of the property whose name matches the argument specified, or if omitted for the property for which the expression is being evaluated, from the fo:table-column whose column-number matches the column for which this expression is evaluated and whose number-columns-spanned also matches any span. If there is no match for the number-columns-spanned, it is matched against a span of 1. If there is still no match, the initial value is returned.

I found this somewhat confusing, so here is the translation. Suppose you have only the following <fo:table-column> element in your <fo:table>

<fo:table-column column-number="2" color="red" font-weight="bold"/>

with this <fo:table-cell> appearing in the second column of your table:

<fo:table-cell number-columns-spanned="2" color="from-table-column()" font-weight="from-table-column()">

The formatter will check to see if there if a 2nd column <fo:table-column> with number-columns-spanned="2". Finding none, it will proceed to use the single column <fo:table-column> and will render the text red and bold




回答2:


Per the Spec

7.28.12 "number-columns-repeated"

XSL Definition: Value: Initial: 1 Inherited: no Percentages: N/A Media: visual

A positive integer. If a non-positive or non-integer value is provided, the value will be rounded to the nearest integer value

greater than or equal to 1.

The "number-columns-repeated" property specifies the repetition of a table-column specification n times; with the same effect as if the fo:table-column formatting object had been repeated n times in the result tree. The "column-number" property, for all but the first, is the column-number of the previous one plus its value of the "number-columns-spanned" property.

Note:

This handles HTML's "colgroup" element. 7.28.13 "number-columns-spanned"

XSL Definition: Value: Initial: 1 Inherited: no Percentages: N/A Media: visual

A positive integer. If a non-positive or non-integer value is provided, the value will be rounded to the nearest integer value

greater than or equal to 1.

For an fo:table-column the "number-columns-spanned" property specifies the number of columns spanned by table-cells that may use properties from this fo:table-column formatting object using the from-table-column() function.

For an fo:table-cell the "number-columns-spanned" property specifies the number of columns which this cell spans in the column-progression-direction starting with the current column.



来源:https://stackoverflow.com/questions/29308671/in-fotable-column-what-is-the-difference-between-the-number-columns-spanned-v

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!