Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries [Thread Prev] >Thread Next - Re: Test for Blank Children Test for Blank ChildrenTo: NULL Date: 8/1/2005 10:38:00 AM Okay, so this is a definite newbie XSL question that I am hoping that someone can help with. Generic Question: If I have a comments section that has 1 or more comment complex type elements, is it possible to determine if there are at least one comment elements that do not have blank children elements? Detailed version: I receive a sample XML file similar to the following: <document> ... <comments> <comment> <author></author> <reference></reference> <date></date> <data></data> </comment> ... </comments> ... </document> The case is that the file will always contain a comment although it may be blank as demonstrated above. I can use <xsl:for-each select="comment"> to loop through each comment but I do not want anything to be written out if the comment is blank. How can I check to see if the fields under <comment> are blank? SCENARIO 1: -------------------------------------------------------------- <comment> <title></title> <author></author> <reference></reference> <date></date> <data></data> </comment> Expected Result: Actual count = 0. print nothing SCENARIO 2: -------------------------------------------------------------- <comment> <title></title> <author>John Doe</author> <reference></reference> <date>08/01/2005</date> <data></data> </comment> <comment> <title>Test</title> <author>John Doe</author> <reference></reference> <date>08/01/2005</date> <data>This is a test</data> </comment> Expected Result: Actual count = 1. Print just the John Doe record How can I strip out or ignore the blank records? The problem is that this goes into a black box that we do not have control over so if there was no comment received then we get. We can fix the front end so that a record has to have a title/reference/data in order to be saved and that will fix SCENARIO 2, but I am still left trying to fix that blank record from SCENARIO 1. I currently just print out everything using the following (please not this is a stripped down version so if there are typos it is from crafting it for this message not for the actual implementation): <xsl:apply-templates select="Comments" \> - and - <xsl:template match="Comments"> <div> <p> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <TR> <TDwidth="50%"> <STRONG>Comments</STRONG> </TD> <TD width="50%"> </TD> </TR> <xsl:for-each select="Comment"> <tr> <td> Title: <xsl:value-of select="title"/> </td> <td> Link: <a> <xsl:attribute name="href"><xsl:value-of select="reference"/></xsl:attribute> <xsl:value-of select="reference"/> </a> </td> </tr> <tr> <td> Comment By: <xsl:value-of select="author"/> </td> <td> Date: <xsl:value-of select="date"/> </td> </tr> <tr> <td colspan="2"> Comment:<br /> <xsl:value-of select="data"/> </td> </tr> </xsl:for-each> </table> </p> </div> </xsl:template> Thank you for you help. Michael | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
