Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Test for Blank Children

From: Michael@-----------.---------.---
To: 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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent