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="ht tp://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:styleshe et 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="WEBCLOS E_XML/ORGANIZATION">
<table width="100%" border="0" cellspacing="0" cellpadding="0" >
<tr>
<td colspan="2">Sta te: <xsl:v alue-of select="STATE"/> &n bsp;City: <xsl:value-of select="CITY"/></td>
</tr>
<tr>
<td colspan="2">&nb sp; <strong>< xsl:value-of select="ORG"/></strong></td>
</tr>
<tr>
<td width="12%" align="right">S tatus: </td>
<td width="88%"><xs l:value-of select="STATUS"/></td>
</tr>
<tr>
<td align="right">M ore Info.: </td>
<td><xsl:valu e-of select="STATUS2 "/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
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="ht tp://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:styleshe et 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="WEBCLOS E_XML/ORGANIZATION">
<table width="100%" border="0" cellspacing="0" cellpadding="0" >
<tr>
<td colspan="2">Sta te: <xsl:v alue-of select="STATE"/> &n bsp;City: <xsl:value-of select="CITY"/></td>
</tr>
<tr>
<td colspan="2">&nb sp; <strong>< xsl:value-of select="ORG"/></strong></td>
</tr>
<tr>
<td width="12%" align="right">S tatus: </td>
<td width="88%"><xs l:value-of select="STATUS"/></td>
</tr>
<tr>
<td align="right">M ore Info.: </td>
<td><xsl:valu e-of select="STATUS2 "/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Comment