【问题标题】:Hiding a table row after filtering in xslt在xslt中过滤后隐藏表格行
【发布时间】:2017-06-30 10:57:24
【问题描述】:

我想在xslt中完成过滤后隐藏表格中的行结构,元素被隐藏但仍然显示行结构。

一个“过滤器”属性被添加到适用的元素中,并且一个变量被引入到样式表中,该变量将匹配这个过滤器属性的值。

例子:

       <multi.document version="1" filterusing="k">
           <table>
     <tbody>
      <row rowsep="0" filtering="k">
       <entry align="left">
        <para.set legal="no">
         <para>
          ----
           </para> 
            </para.set>
            </entry>
             </row>
              </tbody>
              </table>

如果将变量值“a”传递给样式表,则包含“过滤器”属性的元素!=“a”在处理过程中将被忽略。如果元素不包含“过滤器”属性,则它会被正常处理(输出)。

理想情况下,该变量来自 XML 文档之外的来源,但最好有一个根级别的可选属性,该属性可以设置指定应该用于过滤的值。

<xsl:variable name="filter" select="multi.document/@filterusing"></xsl:variable>
<xsl:template match="tbody/row/entry/para.set" mode="table">
    <xsl:choose>
        <xsl:when test="child::para/@change.bar='yes' or ancestor::table/@change.bar='yes'">
            <xsl:choose>
                <xsl:when test="ancestor::row/@filtering">
                    <xsl:choose>
                        <xsl:when test="$filter=ancestor::row/@filtering">
                            <xsl:choose>
                                <xsl:when test="parent::entry/@align='left' and string-length(parent::entry/preceding-sibling::entry/child::para.set/child::para)=0 and not(parent::entry/preceding-sibling::entry)">
                                    <fo:block xsl:use-attribute-sets="table_cell_cb_atts">
                                        <xsl:apply-templates select="para[@language=$active_language]"/>
                                    </fo:block>
                                </xsl:when>
                                <xsl:when test="parent::entry/@align='left' and not(parent::entry/preceding-sibling::entry/child::para.set/child::para/child::node())=0">
                                    <fo:block xsl:use-attribute-sets="table_cell_col2_cb_atts">
                                        <xsl:apply-templates select="para[@language=$active_language]"/>
                                    </fo:block>
                                </xsl:when>
                                <xsl:when test="parent::entry/@align='right'">
                                    <fo:block xsl:use-attribute-sets="table_cell_right_cb_atts">
                  <xsl:apply-templates select="para[@language=$active_language]"/>
                  </fo:block>
                                </xsl:when>
                                <xsl:otherwise>
                                    <fo:block xsl:use-attribute-sets="table_cell_center_cb_atts">
                                        <xsl:apply-templates select="para[@language=$active_language]"/>
                                    </fo:block>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:when>
                        <xsl:otherwise>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:when>
                <xsl:otherwise>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:when>
        <xsl:otherwise>
            <xsl:choose>
                <xsl:when test="ancestor::row/@filtering">
                    <xsl:choose>
                        <xsl:when test="$filter=ancestor::row/@filtering">
                                <fo:block xsl:use-attribute-sets="table_cell_atts">
                                    <xsl:apply-templates select="para[@language=$active_language]"/>
                                </fo:block>
                        </xsl:when>
                        <xsl:otherwise>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:when>
                <xsl:otherwise>
        <fo:block xsl:use-attribute-sets="table_cell_atts">
          <xsl:apply-templates select="para[@language=$active_language]"/>
         </fo:block>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

【问题讨论】:

    标签: xml xslt xsl-fo


    【解决方案1】:

    您的 XSL-FO 包含一个基于 XML row 创建 &lt;fo:table-row&gt; 的部分。

    仅当输入 XML 行与您的过滤器变量匹配时创建 FO 行:

    <xsl: if test="@filtering = $filter">
        <fo:table-row>
            etc. 
    

    【讨论】:

      【解决方案2】:

      下面是用于隐藏行结构的代码,它工作正常

      <xsl:variable name="rowsep">
        <xsl:choose>
        <!-- If this is the last row, rowsep never applies. -->
          <xsl:when test="not(ancestor-or-self::row[1]/following-sibling::row or ancestor-or-self::thead/following-sibling::tbody or ancestor-or-self::tbody/preceding-sibling::tfoot) and not (ancestor-or-self::tbody/parent::tgroup/@sort='yes')">
            <xsl:value-of select="0"/>
          </xsl:when>
          <xsl:when test="ancestor::row/@filtering and ancestor::row/@filtering!=$filter">0</xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="inherited.table.attribute">
              <xsl:with-param name="entry" select="."/>
              <xsl:with-param name="colnum" select="$entry.colnum"/>
              <xsl:with-param name="attribute" select="'rowsep'"/>
            </xsl:call-template>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      
      : -->
      <xsl:variable name="colsep">
        <xsl:choose>
        <!-- If this is the last column, colsep never applies. -->
          <xsl:when test="$following.spans = ''">0</xsl:when>
          <xsl:when test="ancestor::row/@filtering and ancestor::row/@filtering!=$filter">0</xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="inherited.table.attribute">
              <xsl:with-param name="entry" select="."/>
              <xsl:with-param name="colnum" select="$entry.colnum"/>
              <xsl:with-param name="attribute" select="'colsep'"/>
            </xsl:call-template>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-13
        • 1970-01-01
        • 2023-03-17
        • 1970-01-01
        • 2020-11-07
        相关资源
        最近更新 更多