xsl:if problems

Doulos05

Usenet Archive
Joined
Mar 30, 2007
Messages
9
Reaction score
0
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>
<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.
 

roy axenov

Usenet Archive
Joined
Oct 1, 2006
Messages
54
Reaction score
0
Doulos05 said:
<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.
 

CrazyAtlantaGuy

Usenet Archive
Joined
Nov 30, 2005
Messages
7
Reaction score
0
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
 

Doulos05

Usenet Archive
Joined
Mar 30, 2007
Messages
9
Reaction score
0
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,245
Members
248,133
Latest member
DujonT

Latest Threads

Top