Richbuff Posted January 3, 2006 Share Posted January 3, 2006 I have the following XML given to me:<Contact> <id>3283</id> <Name>John Doe</Name></Contact><Contact /><Contact /><Contact />Im using <xsl:for-each> mixed with html to display the contacts in a repeating row table. <xsl:for-each select="Contact"> <tr> <td><xsl:value-of select="id"/></td> <td><xsl:value-of select="Name"/></td> </tr> </xsl:for-each>The Results:ID: 3283 Name: John DoeID: Name:ID: Name:ID: Name:I would like the suppress the empty <Contact /> fields so an html row is not displayed. However the XSLT output does create a row for the empty <Contact /> field with empty data.ID: 3283 Name: John DoeSearched Google and was unable to find a solution. Any help would be appreciated. Thank you. Link to comment Share on other sites More sharing options...
boen_robot Posted January 4, 2006 Share Posted January 4, 2006 Make it a conditional statement. Something like: <xsl:for-each select="Contact"><xsl:if test="id"><tr><td><xsl:value-of select="id"/></td><td><xsl:value-of select="Name"/></td></tr></xsl:if></xsl:for-each> This should make the tr and td only if an ID element exist. Otherwise it will do nothing. Link to comment Share on other sites More sharing options...
Richbuff Posted January 4, 2006 Author Share Posted January 4, 2006 That worked. Simple fix.Thank you for your help. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now