473,375 Members | 1,338 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,375 software developers and data experts.

xsl if test for no child element

4
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">
<tr>
<td colspan="2">State:&nbsp;<xsl:value-of select="STATE"/>&nbsp;&nbsp;&nbsp;City:&nbsp;<xsl:value-of select="CITY"/></td>
</tr>
<tr>
<td colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;<strong><xsl:v alue-of select="ORG"/></strong></td>
</tr>
<tr>
<td width="12%" align="right">Status:&nbsp;</td>
<td width="88%"><xsl:value-of select="STATUS"/></td>
</tr>
<tr>
<td align="right">More Info.:&nbsp;</td>
<td><xsl:value-of select="STATUS2"/></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Feb 11 '08 #1
4 4391
jkmyoung
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>
  4.  
Feb 11 '08 #2
grbeal
4
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
jkmyoung
2,057 Expert 2GB
Maybe:
"substring-after(ENTERED_AT,' ') = 'PM'"
Feb 13 '08 #4
grbeal
4
Maybe:
"substring-after(ENTERED_AT,' ') = 'PM'"
Dude, that did it. Thank you, Thank you, Thank you.
Feb 15 '08 #5

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

Similar topics

4
by: Doug Estep | last post by:
Below is a sample of my XML <MetaData> <Table name="mytable"> <PrimaryKey name="pk"><Column name="mycolumn"/></PrimaryKey> </Table> </MetaData> <Sequencer> <Table name="mytable">
4
by: n_o_s_p_a__m | last post by:
My xml doc has many <title></title> and <title> in it, meaning the nodes have no content (although some do). How can I test for this? I tried title (doesn't work) I tried //title (doesn't work)...
0
by: CoolPint | last post by:
I am trying to write a generic heapsort (of course as a self-exercise) with Iterator interface: something like blow.... But I got into trouble finding out the Iterator to the Child node. If...
1
by: George W. | last post by:
Okay, I'm a C#/XML newbie, and I've been wrestling with this for a while now, checked dotnet sites, articles, MSDN Library, etc. and haven't been able to determine why this is happening. I have...
3
by: Robert | last post by:
I have a number of web projects converted from 1.1 to 2.0 in VS2005. I am methodically seeing the error below: The element 'compilation' has invalid child element 'compilers'. List of...
1
by: adamredwards | last post by:
I have a page with some form elements that are dynamically generated. They are inserted into the dom by first cloning a node, changing the values like name, and then inserted with insertBefore(). ...
3
by: Phil Jenkins | last post by:
Hello there I've inherited some code, which looks like this: <!-- recreate the element (with its namespace) --> <xsl:element name="{local-name()}" namespace="{namespace-uri()}"> <!-- if it...
9
by: hendedav | last post by:
Gang, I am trying to get a regular expression test to work and can't figure out why. I will give you the code below: for (var j=0; j<document.getElementById('cmbList').options.length; j+...
2
by: Claudia Fong | last post by:
Hi, I have a xml document which is like this: <profile document> <Child name = profile1 id = 1> </Child> </profile document>
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
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.