XSL-FO-指定条件可见性
我有一个 HTML 表格,该表格根据其内容而变化。 1-3 列隐藏。 1 列名称更改。一切都取决于内容。
我正在创建此 HTML 表格的 PDF 版本。 PDF 版本使用 apache-FOP
和 fop v1.0
。 PDF 输出在一页上包含 2 个上述表格。我不想为每种可能性的组合创建一个.xsl
。这是大量的重复和维护工作。
我只需将列名与 XML 内容一起传递即可解决列名更改问题。但是,列的条件可见性似乎是一项更具挑战性的任务。
如何设置条件可见性?是否可以?
I'm having difficulty just getting
<fo:table-column visibility="collapse" />
to work. The data still displays with visility set to hidden or collapse. display="none"
looked promising. But, the API doesn't show it as a valid property for a table-column.如果我无法有条件地隐藏列,那么我需要生成 18 个唯一的 xsl
文件...
Currently, my tables are very basic. I do
<fo:block font-size="10pt">
<fo:table table-layout="fixed" width="100%" border-collapse="separate">
<fo:table-column />
<fo:table-column />
<fo:table-column />
<fo:table-column />
<fo:table-column />
<fo:table-column visibility="collapse" />
<fo:table-column />
<fo:table-column />
<fo:table-column />
<fo:table-column />
<fo:table-header>
<fo:table-cell border-width="0.2mm" border-style="solid">
<fo:block>Header 1</fo:block>
</fo:table-cell>
//...9 other headers (these should show/hide as needed)
</fo:table-header>
<fo:table-body>
<xsl:for-each select="Object/type/SomeItem/ProcedureItemCollection">
<fo:table-row>
<fo:table-cell border-width="0.2mm" border-style="solid" >
<fo:block>
<xsl:value-of select="content1"/>
</fo:block>
</fo:table-cell>
//...9 other cells...
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:block>
XML
<Procedure>
<SiteName>Site1</SiteName>//If Site1, don't create column 2
//If Site2, don't create column 2,3,4
//If Site3, create all columns
<itemtype1>
<item><member1></member1><member2></member2></item>
<item><member1></member1><member2></member2></item>
</itemtype1>
<itemtype2>
<item><member1></member1><member2></member2></item>
<item><member1></member1><member2></member2></item>
</itemtype2>
</Procedure>
这样做,我在创建表时几乎没有灵活性。但是,这就是我所知道的一切。
I have an HTML table that varies according to its content. 1-3 columns hide. 1 column name changes. All depending on content.
I am creating a PDF version of this HTML table. The PDF version uses apache-FOP
with fop v1.0
. The PDF output contains 2 of the aforementioned tables on one page. I do not want to create an .xsl
for every combination of possibilities. That's a lot of duplication and maintenance.
I can solve the column name change simply by passing the column name in with the XML content. But, conditional visibility of the columns seems to be a far more challenging task.
How can I setup conditional visibility? Is it possible?
I'm having difficulty just getting
<fo:table-column visibility="collapse" />
to work. The data still displays with visility set to hidden or collapse. display="none"
looked promising. But, the API doesn't show it as a valid property for a table-column.If I can't conditionally hide a column then I'll need to produce 18 unique xsl
files...
Currently, my tables are very basic. I do
<fo:block font-size="10pt">
<fo:table table-layout="fixed" width="100%" border-collapse="separate">
<fo:table-column />
<fo:table-column />
<fo:table-column />
<fo:table-column />
<fo:table-column />
<fo:table-column visibility="collapse" />
<fo:table-column />
<fo:table-column />
<fo:table-column />
<fo:table-column />
<fo:table-header>
<fo:table-cell border-width="0.2mm" border-style="solid">
<fo:block>Header 1</fo:block>
</fo:table-cell>
//...9 other headers (these should show/hide as needed)
</fo:table-header>
<fo:table-body>
<xsl:for-each select="Object/type/SomeItem/ProcedureItemCollection">
<fo:table-row>
<fo:table-cell border-width="0.2mm" border-style="solid" >
<fo:block>
<xsl:value-of select="content1"/>
</fo:block>
</fo:table-cell>
//...9 other cells...
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:block>
XML
<Procedure>
<SiteName>Site1</SiteName>//If Site1, don't create column 2
//If Site2, don't create column 2,3,4
//If Site3, create all columns
<itemtype1>
<item><member1></member1><member2></member2></item>
<item><member1></member1><member2></member2></item>
</itemtype1>
<itemtype2>
<item><member1></member1><member2></member2></item>
<item><member1></member1><member2></member2></item>
</itemtype2>
</Procedure>
Doing it this way, I have little flexibility in creating the table. But, this is all I know how to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过大量修改后,我发现我可以使用 xsl:when 和变量添加/删除列。
首先创建一个变量,
然后有条件地创建表的 3 个元素(列定义、标题、主体)。从列定义开始...
然后是标题
最后是正文
After a lot of tinkering it turns out that I can add/remove columns using
xsl:when
and a variable.First create a variable
Then conditionally create the 3 elements of the table (column definition, header, body). Starting with the column definition...
Then the header
Finally, the body