471,321 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

xsl if test for no child element

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.

However, when there are no School Closings (weather is nice), the XML that is output contains only a root element and no child nodes or tags inside the root. I'd like to setup an xsl if (or something) that would output the HTML text "There are no School Closings today.", when this XML file is empty.

I've fumbled around with several different xsl code bits I've googled on the web, but nothing seems to work. I appreciate any help, its my first experience with XML.

Here's the code from my Dreamweaver created XSLT fragment. Where would I put the xsl if test?

<?xml version="1.0" encoding="iso-8859-1"?><!-- DWXMLSource="http://www.wbcl.org/cgsclosing/webclose.xml" -->
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp " ">
<!ENTITY copy "©">
<!ENTITY reg "®">
<!ENTITY trade "™">
<!ENTITY mdash "—">
<!ENTITY ldquo "“">
<!ENTITY rdquo "”">
<!ENTITY pound "£">
<!ENTITY yen "¥">
<!ENTITY euro "€">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="iso-8859-1"/>
<xsl:template match="/">

<xsl:for-each select="WEBCLOSE_XML/ORGANIZATION">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<td colspan="2">State:&nbsp;<xsl:value-of select="STATE"/>&nbsp;&nbsp;&nbsp;City:&nbsp;<xsl:value-of select="CITY"/></td>
<td colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;<strong><xsl:v alue-of select="ORG"/></strong></td>
<td width="12%" align="right">Status:&nbsp;</td>
<td width="88%"><xsl:value-of select="STATUS"/></td>
<td align="right">More Info.:&nbsp;</td>
<td><xsl:value-of select="STATUS2"/></td>
Feb 11 '08 #1
4 4285
2,057 Expert 2GB
I'm guessing no closings means no "WEBCLOSE_XML/ORGANIZATION" nodes?
Add an <xsl:if> at the beginning:
Expand|Select|Wrap|Line Numbers
  1. <xsl:if test="not(WEBCLOSE_XML/ORGANIZATION)">
  2.   <xsl:text> No schools closed today </xsl:text>
  3. </xsl:if>
Feb 11 '08 #2
Thanks jkmyoung,

That has worked great. I have another question if you could help me out.

I also want to create another report from the XML file that will show all records that were entered after Noon. I've got this element in the XML file, here's an example: <ENTERED_AT>08:30:25 AM</ENTERED_AT>. How do I code the 'xsl if' to test for time?

This doesn't seem to work: ENTERED_AT > 12. There must be some way to declare the ENTERED_AT element as a time value?
Feb 13 '08 #3
2,057 Expert 2GB
"substring-after(ENTERED_AT,' ') = 'PM'"
Feb 13 '08 #4
"substring-after(ENTERED_AT,' ') = 'PM'"
Dude, that did it. Thank you, Thank you, Thank you.
Feb 15 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by n_o_s_p_a__m | last post: by
3 posts views Thread by Phil Jenkins | last post: by
9 posts views Thread by hendedav | last post: by
2 posts views Thread by Claudia Fong | last post: by
reply views Thread by rosydwin | last post: by

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.