开发者

Problem with if statement in xslt

I am trying to display an edit button for each row if logged in as admin.

XML:

<vendors>
   <vendor id="1" name="Microsoft" description="1" odd="1"></vendor>
   <vendor id="2" name="Apple" description="1"></vendor>
   <vendor id="3" name="Google"开发者_StackOverflow description="1" odd="1"></vendor>
   <security ADMIN="1"></security>
</vendors>

XSLT:

<xsl:template match="vendors">
  <table>
    <thead>
      <tr>
        <xsl:if test="/vendors/security/@ADMIN = '1'">
          <td></td>
        </xsl:if>
        <td>Name</td>
        <td>Description</td>
      </tr>
    </thead>
      <tbody>
        <xsl:for-each select="vendor">
          <tr>
            <xsl:if test="@odd = '1'">
              <xsl:attribute name="class">odd</xsl:attribute>
            </xsl:if>
            <xsl:if test="/vendors/security/@ADMIN = '1'">
              <th><a href="#"><img src='edit.gif'></a></th>
            </xsl:if>
            <td title='Name'><xsl:value-of select="@name" /></td>
            <td title='Description'><xsl:value-of select="@description" /></td>
          </tr>
        </xsl:for-each>
      </tbody>
    </table>
  </div>
</xsl:template>

Right now this doesn't work. When logged in as admin (@ADMIN = "1"), everything works. When logged in with @ADMIN = "", none of the table cells are displayed (only empty rows).


Apart a problem in the output document (not closed img tag and not open div) the XSLT shown is correct and should show the cells Name/Description even when @ADMIN is "" (tested using Saxon).

You might also compare integers directly, as follows:

test="/vendors/security/@ADMIN = 1"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜