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:

    <ref_sheet>

    <item>
    <date>2007/04/06</date>
    <product>124567</product>
    <description>TAB DIVIDERS</description>
    <note>Description of problem here</note>
    <expired>true</expired>
    </item>

    <item>
    <date>2007/04/25</date>
    <product></product>
    <description>Diploma/Certificate Folders</description>
    <note>description of problem here. </note>
    <expired>false</expired>
    </item>

    </ref_sheet>

    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/
    Transform">
    <xsl:eek:utput method="html"/>

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

    <xsl:apply-templates/>
    </body>
    </html>
    </xsl:template>

    <xsl:template match="ref_sheet">
    <table border="1">
    <tr>
    <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-->
    </tr>
    <xsl:apply-templates/>
    </table>
    </xsl:template>

    <xsl:template match="item">
    <xsl:if test="expired = false">
    <tr>
    <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>
    </tr>
    </xsl:if>
    </xsl:template>
    </xsl:stylesheet>

    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
    1. Advertising

  2. Martin Honnen, May 3, 2007
    #2
    1. Advertising

  3. Doulos05

    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

    <expired>
    false
    </expired>

    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
    #3
  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
     
    CrazyAtlantaGuy, May 3, 2007
    #4
  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
    #5
    1. Advertising

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
    Replies:
    0
    Views:
    1,052
    Kevin Flood
    Sep 8, 2004
  2. Kevin Flood
    Replies:
    1
    Views:
    2,809
    Kevin Flood
    Sep 13, 2004
  3. Klaus Friese
    Replies:
    0
    Views:
    493
    Klaus Friese
    Nov 22, 2004
  4. Ray Tayek
    Replies:
    3
    Views:
    537
    Ray Tayek
    Nov 30, 2003
  5. Replies:
    1
    Views:
    3,686
    A. Bolmarcich
    May 27, 2005
Loading...

Share This Page