xsl:if problems

Discussion in 'XML' started by Doulos05, May 3, 2007.

  1. Doulos05

    Doulos05 Guest

    Ok, this seems like it should be easy, but it has escaped me. Here is
    my xml file:


    <description>TAB DIVIDERS</description>
    <note>Description of problem here</note>

    <description>Diploma/Certificate Folders</description>
    <note>description of problem here. </note>


    Here is the stylesheet:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
    <xsl:eek:utput method="html"/>

    <xsl:template match="/">
    <input type="button" value="Close this window" onclick="self.close()"/


    <xsl:template match="ref_sheet">
    <table border="1">
    <th align="center">Date</th><!--Column 1-->
    <th align="center">Product ID</th><!--Column 2-->
    <th align="center">Product Description</th><!--Column3-->
    <th align="center">Notes</th><!--Column4-->
    <th align="center">expired</th><!--Column5-->

    <xsl:template match="item">
    <xsl:if test="expired = false">
    <td><xsl:copy-of select="date"/></td>
    <td><xsl:copy-of select="product"/></td>
    <td><xsl:copy-of select="description"/></td>
    <td><xsl:copy-of select="note"/></td>
    <td><xsl:copy-of select="expired"/></td>

    This is being transformed client-side using MSXML in IE 6.x. It won't
    correctly process the if statement. What I want it to do is only
    display the items which are not expired (for which expired = false).
    What it does is give me the table header row, but it does not return
    any of the non-expired items.
    Doulos05, May 3, 2007
    1. Advertisements

  2. Martin Honnen, May 3, 2007
    1. Advertisements

  3. roy axenov

    roy axenov Guest

    Doulos05 wrote:
    > <xsl:if test="expired = false">

    So you want your XSLT processor to interpret 'expired' as a
    name of an element but 'false' as a string literal? How the
    hell is it supposed to know the difference?

    <xsl:if test="expired='false'">

    What you wrote does something else entirely.

    Note that the expression given wouldn't work for


    unless you use <xsl:strip-space/>.

    Figuring out what

    <xsl:if test="expired=false()">

    would do is left as an exercise for the reader. Reading a
    good XSLT/XPath tutorial is strongly recommended before you
    start tinkering.

    > What I want it to do is only display the items which are
    > not expired (for which expired = false). What it does is
    > give me the table header row, but it does not return any
    > of the non-expired items.

    Think before you type.

    roy axenov
    roy axenov, May 3, 2007
  4. The node itsself will never equal "false", you want to see if it's
    text content equals "false".

    <xsl:if test="expired/.=false">

    An alternate technique would be to only include the expired tag
    <expired/> if the item was expired, leaving it out if the item
    wasn't. Then just test for the presence of the tag.

    <xsl:if test="expired">

    I'm no expert either, but I would give these two approaches a try.

    Good luck,

    CrazyAtlantaGuy, May 3, 2007
  5. Doulos05

    Doulos05 Guest

    Yeah, I figured it was something obvious. Should have caught on to
    that, but I wasn't thinking enough like a programmer. I couldn't
    figure it out.

    On a related note, I'm still kind of new to this whole programming
    thing, so if anyone has any good suggestions for tutorials or examples
    for XML, I would welcome the advice. I have been using the W3C schools
    tutorials (which never uses <xsl:if> to test against a string literal,
    which is why it didn't cross my mind that the string needed to be in
    quotes) but I'll go anywhere for good information. Thank you for the
    fix and advice.

    Jonathan B.
    Doulos05, May 4, 2007
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Flood
    Kevin Flood
    Sep 8, 2004
  2. Kevin Flood
    Kevin Flood
    Sep 13, 2004
  3. Klaus Friese
    Klaus Friese
    Nov 22, 2004
  4. Ray Tayek
    Ray Tayek
    Nov 30, 2003
  5. Replies:
    A. Bolmarcich
    May 27, 2005

Share This Page