[xsl] Best way to substitute a empty child node to the value 'NULL'

Subject: [xsl] Best way to substitute a empty child node to the value 'NULL'
From: Tariq Ahsan <tariqahsan@xxxxxxxxx>
Date: Wed, 6 Feb 2008 21:23:27 -0800 (PST)
Hi,

I am a newbie to XSLT. I am trying to write a simple
xslt script to transform a xml file with records to a
SQL file which will have separate SQL insert
statements. But some of the nodes of this input xml
file will contain empty nodes. I would like to
transform all of the empty nodes to the value of
'NULL'. Here is a sample content of the input xml file
-

<data>
    <row>
      <TAG1>123</TAG1>
      <TAG2>ABC</TAG2>
      <TAG3 />
      <TAG4 />
    </row>
    <row>
      <TAG1>999</TAG1>
      <TAG2>XYZ</TAG2>
      <TAG3 />
      <TAG4 />
    </row>

</data>
      
Here's the what I have now in the xsl file -

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
	<xsl:output indent="yes" />
	
<xsl:template match="/">
<xsl:for-each select="data/row">
INSERT INTO DBO.TEST
(COL1, COL2, COL3, COL4) VALUES(
<xsl:value-of select="normalize-space(TAG1)"/>, 
'<xsl:value-of select="normalize-space(TAG2)"/>',
'<xsl:value-of select="normalize-space(TAG3)"/>',
<xsl:value-of select="normalize-space(TAG4)"/>,
);
</xsl:for-each>
</xsl:template>
</xsl:stylesheet> 

Here's the output sql file should have

insert into DBO.TEST (COL1, COL2, COL3, COL4) VALUES
(123, 'ABC', NULL, NULL);
insert into DBO.TEST (COL1, COL2, COL3, COL4) VALUES
(999, 'XYZ', NULL, NULL);

Would appreciate if I could get a simple solution for
this problem.

Thanks

Tariq Ahsan


      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 

Current Thread