homepage Welcome to WebmasterWorld Guest from 54.167.179.48
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
Conditional statement
nbozic

10+ Year Member



 
Msg#: 3112749 posted 4:05 am on Oct 8, 2006 (gmt 0)

Hi,

I'm new to XML and I'm having issues with a simple conditional statement.

Here's the XSL side, including the conditional statement:

----------------------------------------

<?xml version="1.0"?>
<HTML xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:choose>
<xsl:when test="response/totalresults > 0">
Results <strong><xsl:value-of select="response/start"/></strong> - <strong><xsl:value-of select="response/end"/></strong>
out of <strong><xsl:value-of select="response/totalresults"/></strong> total found.
<xsl:for-each select="response/results/result">
<DIV STYLE="background-color:teal; color:white; padding:4px">
<SPAN STYLE="font-weight:bold; color:white"><xsl:value-of select="jobtitle"/></SPAN>
- <xsl:value-of select="jobtitle"/>
</DIV>
<DIV STYLE="margin-left:20px; margin-bottom:1em; font-size:10pt">
<xsl:value-of select="description"/>
<SPAN STYLE="font-style:italic">
(<xsl:value-of select="calories"/> calories per serving)
</SPAN>
</DIV>
</xsl:for-each>
</xsl:when>

<xsl:otherwise>
Sorry, we found no matches for "whatever."
</xsl:otherwise>

</xsl:choose>

</HTML>

----------------------------------------

Here's XML structure:

-----------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<response>
<query>blablabla</query>
<location>wherever</location>
<dupefilter>true</dupefilter>
<highlight>true</highlight>
<totalresults>0</totalresults>
<start>1</start>
<end>0</end>
<results />
</response>

-----------------------------------------

And of course, the error message:

-----------------------------------------

msxml3.dll error '80004005'

Expected token 'eof' found '>'. response/totalresults -->><-- 0

----------------------------------------

I would appreciate any pointers.

Thanks.

 

daveVk

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3112749 posted 1:43 pm on Oct 8, 2006 (gmt 0)

I suspect the statement

<xsl:when test="response/totalresults > 0">

try

<xsl:when test="response/totalresults!= 0">

if you need to use > suspect it needs escaping &gt; or \> maybe? Thats my guess, but not experienced in XSL.

nbozic

10+ Year Member



 
Msg#: 3112749 posted 11:02 pm on Oct 8, 2006 (gmt 0)

daveVk, I tried your suggestions but for some reason it still doesn't work. I'm not experienced with XSL either and it's pretty frustrating.

daveVk

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3112749 posted 5:50 am on Oct 9, 2006 (gmt 0)

[w3schools.com...] by this example you may need to wrap stylesheet within <stylesheet> and <template> tags and yes they use &gt; , eg <xsl:when test="price&gt;'10'"> why '10' and not just 10?

nbozic

10+ Year Member



 
Msg#: 3112749 posted 8:13 pm on Oct 9, 2006 (gmt 0)

I got it to work - I had stuff all over the place and not properly formatted... as you said it had something to do with the <stylesheet> and <template> tags being in right order.
The comparison works wine with numbers that are not enclosed within single quotes.

Thanks.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved