Testing if nodes empty

webmasterbeta

New Member
I am building reports from XML files and sometimes there will be a bill to address and sometimes not. How do I (using XSLT or Javascript)determine if the nodes actually hold info? If they do not have anything in them then I need to build my table displaying the info differently.

For example (this is what I tried but does not work, I am new at this)



XML
**********
<invoice>
<billto>
<firstname>Joe</firstname>
<lastname>Pesche</lastname>
<contact></contact>
<address1>PO Box 5555</address1>
<address2></address2>
<city>Youngstown</city>
<state>OH</state>
<zip>44503</zip>
<email></email>
<priphone>330-744-1222</priphone>
<secphone></secphone>
</billto>
</invoice>


XSLT
*********
<xsl:if test="string-length('invoice/billto/address1') > 0">
<b>Bill to</b>
<table width="50%" cellpadding="3" border="1">
<tr>
<td>
<xsl:value-of select="invoice/billto/priphone"/><p></p>
<xsl:value-of select="invoice/billto/lastname"/>, <xsl:value-of select="invoice/billto/firstname"/><br/>
<xsl:value-of select="invoice/billto/address1"/><br/>
<xsl:value-of select="invoice/billto/city"/>,
<xsl:value-of select="invoice/billto/state"/>
<xsl:value-of select="invoice/billto/zip"/>
</td>
</tr>
</table>
</xsl:if>



So ultimately if my XML page does not have info in these fields I do not want any labels or info to show up. SO everything inside the if statement (if empty) I do not want to show up. I have other areas where this is needed so i need a solution so the page is not cluttered with empty data sets with borders.

Thanks for any help with this.
 
Back
Top