I have an XML and XSLT. I开发者_C百科 want to use the if condition to check if an element is 0, if it is then hide it i.e display nothing. IF 0 is found, simply display a blank cell.
Here is the basic concept:
XML
 <Sheet1>
     <Build>0</Build>
     <Item>X</Item>
     <T1>0:06:00</T1>
     <T2>0:14:15</T2>
     <T3>0:07:22</T3>
 </Sheet1>
XSLT
<table border="1">
    <tr bgcolor="#dccdc">
        <th align="center">Build</th>
        <th align="center">Item</th>
        <th align="center">T1</th>
        <th align="center">T2</th>
        <th align="center">T3</th>
    </tr>  
    <xsl:for-each select="Sheet1">
        <tr>
            <td bgcolor="#F2F5A9">
                <xsl:value-of select="Build" />
            </td>
            <td bgcolor="#F2F5A9">
                <xsl:value-of select="Item" />
            </td>
            <td bgcolor="#F2F5A9">
                <xsl:value-of select="T1" />
            </td>
            <td bgcolor="#F2F5A9">
                <xsl:value-of select="T2" />
            </td>
            <td bgcolor="#F2F5A9">
                <xsl:value-of select="T3" />
            </td>
         </tr>
     </xsl:for-each>
</table>
What I want to do is when Build element = 0 i want it to print nothing, so i tried putting an xsl:if around the item in the XSLT:
<xsl:if test="Build!='0'">
    <td bgcolor="#F2F5A9">
        <xsl:value-of select="Build" />
    </td>
</xsl:if>
but this does not seem to work, i get a blank output file.
any ideas?
Simplest solution is to write
    <td bgcolor="#F2F5A9">
        <xsl:value-of select="Build[. != 0]" />
    </td>
A correct approach is also (fragment):
  <td bgcolor="#F2F5A9">
    <xsl:if test="Build[text()!='0']">
      <xsl:value-of select="Build" />
    </xsl:if>
  </td>
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论