473,657 Members | 2,806 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>TA B DIVIDERS</description>
<note>Descripti on of problem here</note>
<expired>true </expired>
</item>

<item>
<date>2007/04/25</date>
<product></product>
<description>Di ploma/Certificate Folders</description>
<note>descripti on of problem here. </note>
<expired>fals e</expired>
</item>

</ref_sheet>

Here is the stylesheet:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:styleshe et 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.c lose()"/
>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="ref_shee t">
<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="descrip tion"/></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 2965
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=f alse()">

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
2341
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 statement to only print the Award row if it's not blank. (I'd like to format this with a list item, and not have a list item display w/o any data by it.) Can someone please point me in the direction of some tutorials/syntax
3
3893
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> <xsl:number count="LoanRecord" format="1"/><br/> Loan ID:<xsl:value-of select="loan_no"> </xsl:value-of><br/> Calculated CLTV:<xsl:value-of select="format-number (curr_balance div
9
8314
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"/> On the XSLt file relayed to this XML, i wrote in green the attribute value if Attribute "Esito" is "Ok". I mean, something, like this:
2
10805
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
3596
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 test="$var:v141=&quot;true&quot;"> <!-- This doesn't work --> <xsl:if test="string($var:v141)=&quot;true&quot;">
5
2331
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 Step</title> <author>Michael Halvorsen</author> <subject>Programming</subject>
4
2432
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" and include the extra html as shown below if the test passes. The rest of the code validates and so, I hope, works. What am I doing so very wrong here?
4
4410
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 FTP'd to my web host when the Access database is changed. I'm using Dreamweaver to create an XSLT fragment to read the XML file and include the HTML output into my ASP page. It works fine to display the XML data, the School Closings, in my web page. ...
3
2344
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 and then the xslt sample code that is not matching. please look and if it jumps right off the page give me a tip on why it didnt select the data. i think for most xslt people this will be easy. i want the if to work if it is null because
0
8316
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8833
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8737
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8509
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8610
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6174
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5636
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.