xslt - XSL-FO- 指定条件可见性

标签 xslt xsl-fo apache-fop

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

我正在创建此 HTML 表格的 PDF 版本。 PDF版本使用apache-FOPfop v1.0 . PDF 输出在一页上包含上述表格中的 2 个。我不想创建 .xsl对于每种可能性的组合。这是很多重复和维护。

我可以通过将列名与 XML 内容一起传入来解决列名更改。但是,列的条件可见性似乎是一项更具挑战性的任务。

如何设置条件可见性?是否可以?

我很难获得 <fo:table-column visibility="collapse" />上类。数据仍然显示,可见性设置为隐藏或折叠。 display="none"看起来很有希望。但是,API doesn't show it as a valid property对于表列。

如果我不能有条件地隐藏一列,那么我需要生成 18 个唯一的 xsl文件...

目前,我的表格非常基础。我愿意

<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>

这样做,我在创建表格时几乎没有灵活性。但是,这就是我所知道的一切。

最佳答案

经过大量修补后,我发现我可以使用 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>

最后, 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>

关于xslt - XSL-FO- 指定条件可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7570657/

相关文章:

javascript - 我如何使用 XML 设计样式

xml - 将平面层次结构转换为 XSLT 深度的嵌套层次结构

static - xsl-fo header - 左侧图像,右侧三行文本,顶部对齐

java - Apache FOP API 引用

java - 无法使用 Spring boot 2.1.6.RELEASE 和 Apache 2.4 FOP 编译应用程序

xslt - 如何使用XSLT根据其依赖关系对某些XML元素进行排序?

xml - 非常简单的 XSL/XPath 健全性检查

ms-word - 如何使用 Apache FOP 将 Word 2007 文档转换为 PDF

c# - XML 到 XSL-FO C#.NET

jpeg - Apache-FOP-减少嵌入PDF的图像大小