473,320 Members | 1,947 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,320 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 4387
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.