468,530 Members | 1,553 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,530 developers. It's quick & easy.

xsl:if problems

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:output 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.

May 3 '07 #1
4 2791
Doulos05 wrote:
<xsl:if test="expired = false">
<xsl:if test="expired = 'false'">


Martin Honnen
May 3 '07 #2
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
May 3 '07 #3
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,


May 3 '07 #4
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:ifto 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.

May 4 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by LisaDi | last post: by
9 posts views Thread by Andrea Maschio | last post: by
2 posts views Thread by Jørn Tommy Kinderås | last post: by
3 posts views Thread by Eric Theil | last post: by
5 posts views Thread by Luke Vogel | last post: by
4 posts views Thread by grbeal | last post: by
3 posts views Thread by z1 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.