【发布时间】: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>
【问题讨论】: