XSL-FO-指定条件可见性

发布于 2024-12-06 21:50:30 字数 2850 浏览 1 评论 0原文

我有一个 HTML 表格,该表格根据其内容而变化。 1-3 列隐藏。 1 列名称更改。一切都取决于内容。

我正在创建此 HTML 表格的 PDF 版本。 PDF 版本使用 apache-FOPfop 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心意如水 2024-12-13 21:50:30

经过大量修改后,我发现我可以使用 xsl:when 和变量添加/删除列。

首先创建一个变量,

<xsl:variable name="SiteName" select="Procedure/SiteName" />

然后有条件地创建表的 3 个元素(列定义、标题、主体)。从列定义开始...

          <xsl:choose>
            <xsl:when test="$SiteName = 'Site1'">
              <fo:table-column />//column 2
            </xsl:when>
          </xsl:choose>

然后是标题

           <xsl:choose>
              <xsl:when test="$SiteName = 'Site1'">
                    <fo:table-cell border-width="0.2mm" border-style="solid">
                      <fo:block>Column2</fo:block>
                    </fo:table-cell>
              </xsl:when>
            </xsl:choose>

最后是正文

                <xsl:choose>                                           
                        <xsl:when test="$SiteName = 'Site1'">
                          <fo:table-cell border-width="0.2mm" border-style="solid" >
                            <fo:block>
                              <xsl:value-of select="column2value"/>
                            </fo:block>
                          </fo:table-cell>
                        </xsl:when>                          
                </xsl:choose>

After a lot of tinkering it turns out that I can add/remove columns using xsl:when and a variable.

First create a variable

<xsl:variable name="SiteName" select="Procedure/SiteName" />

Then conditionally create the 3 elements of the table (column definition, header, body). Starting with the column definition...

          <xsl:choose>
            <xsl:when test="$SiteName = 'Site1'">
              <fo:table-column />//column 2
            </xsl:when>
          </xsl:choose>

Then the header

           <xsl:choose>
              <xsl:when test="$SiteName = 'Site1'">
                    <fo:table-cell border-width="0.2mm" border-style="solid">
                      <fo:block>Column2</fo:block>
                    </fo:table-cell>
              </xsl:when>
            </xsl:choose>

Finally, the body

                <xsl:choose>                                           
                        <xsl:when test="$SiteName = 'Site1'">
                          <fo:table-cell border-width="0.2mm" border-style="solid" >
                            <fo:block>
                              <xsl:value-of select="column2value"/>
                            </fo:block>
                          </fo:table-cell>
                        </xsl:when>                          
                </xsl:choose>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文