473,327 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

xsl:if problems

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

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

--

Martin Honnen
http://JavaScript.FAQTs.com/
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

<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
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,

CrazyAtlantaGuy

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: LisaDi | last post by:
Hi, In my XML file, I have multiple 'Job' nodes. Within that node, there is an 'Award' item. Not every job has an 'Award' populated. :-( When I output this in XSL, I would like to use an IF...
3
by: Lizard | last post by:
OK, total newbie here, so this may be a mind-numbingly dumb question AND I may be phrasing it badly. I have an xsl:template which looks like this: <xsl:template match="LoanRecord"> <hr>...
9
by: Andrea Maschio | last post by:
Hi, i have a terrible noobie frustration formatting an XML file like this: <Dipendente Id="1" Anno="2003" Nome="pippo" Cognome="pippi" Nato_il="10/03" Email="pippo@emailprovider.it" Esito="ok"/>...
2
by: Jørn Tommy Kinderås | last post by:
I need to get nodes in a xml file that match one out of two parameters...but how can I create a or statemement with <xsl:if>? E.G ---xml-- ... <movie> <title>T2</title> </movie> <movie>
3
by: Eric Theil | last post by:
I'm at my wit's end with this one. Within an xsl:if test, I'm not able to get 2 variables to properly evaluate if one of them is wrapped within a string function. <!-- This works --> <xsl:if...
5
by: Luke Vogel | last post by:
Hi all, Probably a really basic question, but I cant find an answer ... I have an xml file of books something like: <product> <isbn>0-735-61374-5</isbn> <title>Microsoft Visual Basic Step By...
4
by: mark4asp | last post by:
I'm getting a problem with this code and I think the offending linke is : <xsl:if test="$folder = 'Search'"> I want to test the value of the Folder element for a value of precisely "Search"...
4
by: grbeal | last post by:
How do I test for a child element with xsl if condition? We have a vendor application that outputs an XML file containing records of School Closings due to inclement weather. That XML file gets...
3
by: z1 | last post by:
hi- i am fooling around with soap and weather templates. for some reason either this if or select is failing. i am very new to xml and found this code at another site. i can show you the xml...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.