xslt删除表列时所有特定值 [英] xslt remove table column when all specific value

查看:32
本文介绍了xslt删除表列时所有特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用XSLT,当一列仅包含"0.00"或-"时,我需要删除一个完整的表列(标题+主体单元格).

Using XSLT, I need to remove a complete table column (header + body cells) when a column contains only "0.00" or "-".

即如果一列或多列的单元格中的所有值均为0.00/-,则应删除整列.

i.e. If all the values in the cells of one or more columns are 0.00/- then the whole column(s) should be removed.

推荐答案

我假设您的意思不是说该列的所有数据单元格是否均为0.00/-,然后删除它,而不仅仅是其中之一.如果我有误解,请提出建议,我将相应地更新解决方案样式表.

I have assumed that you mean't to say if all the data cells of the column are 0.00/- then remove it, not just one of them. If I have misunderstood, please advise and I will update the solution style-sheets accordingly.

创建表有很多不同的方法和选项,因此您的解决方案将需要根据表的类型和结构进行调整.这里显示的是一种简单表格形式的解决方案.

There are a lot of different ways and options to create tables, and so your solution will need to be adjusted to the type and structure of your table. Shown here is a solution for a simple form of table.

此XSLT 1.0样式表...

This XSLT 1.0 style-sheet...

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template name="ident" match="@*|node()">
 <xsl:copy>
   <xsl:apply-templates select="@*|node()"/>
 </xsl:copy>
</xsl:template>

<xsl:template match="td">
  <xsl:variable name="col" select="count(preceding-sibling::td)+1" />
  <xsl:if test="../../tr/td[$col][. != '0.00'][. != '-']">
    <xsl:call-template name="ident" />
  </xsl:if>  
 </xsl:template>

</xsl:stylesheet>

...应用于此输入文档时...

...when applied to this input document...

<table>
  <th>
    <td>Contestant</td><td>Score</td><td>Country</td>
  </th> 
  <tr>
    <td>Jack</td><td>0.00</td><td>AUS</td>
  </tr> 
  <tr>
    <td>Jill</td><td>-</td><td>-</td>
  </tr> 
</table> 

...将产生...

...will yield...

<table>
  <th>
    <td>Contestant</td>
    <td>Country</td>
  </th>
  <tr>
    <td>Jack</td>
    <td>AUS</td>
  </tr>
  <tr>
    <td>Jill</td>
    <td>-</td>
  </tr>
</table>

仅删除一列-带有所有空"非标题单元格的列.

Only one column is removed - the one with all "empty" non-header cells.

这是等效的XSLT 2.0 ...

And here is the XSLT 2.0 equivalent...

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="@*|node()">
 <xsl:copy>
   <xsl:apply-templates select="@*|node()"/>
 </xsl:copy>
</xsl:template>

<xsl:template match="td[ not(
  for $c in count(preceding-sibling::td)+1 return
    ../../tr/td[$c][.!='0.00'][.!= '-']  )]" />

</xsl:stylesheet>

这篇关于xslt删除表列时所有特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆