[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Best way to substitute a empty child node to the value

Subject: 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)
 Best way to substitute a empty child node to the value
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.