Subject: [xsl] Check for null value and Check if child tag exists From: Priya Pinto <Priya.P@xxxxxxxxxxxxxxxxxx> Date: Sun, 15 Apr 2001 15:38:08 +0400 |
Hi, I'm working on transfering data from and XML file to Oracle Database. For this I need to convert my XML File into the canonical form with the help of an XSLT. These are a few problems am facing 1) I need to be able to check if a particular tag has one or more child tags and be able to get their values. 2) I also need to be able to finout if a tag has a null value. Here is a sample of my xml file and the xsl file and the xml I need to get. The original xml file <?xml version="1.0" encoding="UTF-8"?> <World> <Country Name="Afghanistan"> <Region Name="Herat"> <City Name="Herat" Time="GMT+04:30"></City> </Region> <City Name="Kabul" Time="GMT+04:30"></City> <City Name="Kandahar" Time="GMT+04:30"></City> <City Name="Mazar-e Sharif" Time="GMT+04:30"></City> </Country> <Country Name="Albania"> <City Name="Shkoder" Time="GMT+01:00"></City> <City Name="Tirane" Time="GMT+01:00"></City> </Country> <Country Name="Algeria"> <Region Name="Algiers"> <City Name="Alger" Time="GMT+01:00"></City> <City Name="Annaba" Time="GMT+01:00"></City> <City Name="Blida" Time="GMT+01:00"></City> <City Name="Constantine" Time="GMT+01:00"></City> <City Name="Oran" Time="GMT+01:00"></City> <City Name="Skikda" Time="GMT+01:00"></City> </Region> </Country> <Country Name="American Samoa"> <City Name="Pago Pago" Time="GMT-11:00"></City> </Country> </World> The XSL file <rowset xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0"> <xsl:for-each select="World/Country"> <xsl:choose> <xsl:when test="World/Country[Region/@Name=' ']"> <row> <country><xsl:value-of select="@Name"/></country> <region><xsl:value-of select="Region/@Name"/></region> <city><xsl:value-of select="Region/City/@Name"/></city> </row> <xsl:if test="Region/text()"> <row> <country1><xsl:value-of select="@Name"/></country1> <city1><xsl:value-of select="City/@Name"/></city1> </row> </xsl:if> </xsl:when> <xsl:otherwise> <row> <country2><xsl:value-of select="@Name"/></country2> <region2><xsl:value-of select="Region/@Name"/></region2> <city2><xsl:value-of select="Region/City/@Name"/></city2> </row> </xsl:otherwise> </xsl:choose> <xsl:if test="City"> <xsl:for-each select="City"> <row> <country3><xsl:value-of select="Country/@Name"/></country3> <city3><xsl:value-of select="@Name"/></city3> </row> </xsl:for-each> </xsl:if> </xsl:for-each> </rowset> This is the file I require but have not suceeded as yet <?xml version="1.0" encoding="UTF-8"?> <rowset> <row> <country>Afghanistan</country> <region/> <city>Herat</city> </row> <row> <country>Afghanistan</country> <region/> <city>Kabul</city> </row> <row> <country>Afghanistan</country> <region/> <city>Kandahar</city> </row> <row> <country>Afghanistan</country> <region/> <city>Mazar-e Sharif</city> </row> <row> <country>Albania</country> <region/> <city>Shkoder</city> </row> <row> <country>Albania</country> <region/> <city2>Tirane</city2> </row> <row> <country>Algeria</country> <region>Algiers</region> <city>Alger</city> </row> <row> <country>Algeria</country> <region>Algiers</region> <city>Annaba</city> </row> <row> <country>Algeria</country> <region>Algiers</region> <city>Blida</city> </row> <row> <country>Algeria</country> <region>Algiers</region> <city>Constantine</city> </row> <row> <country>Algeria</country> <region>Algiers</region> <city>Oran</city> </row> <row> <country>Algeria</country> <region>Algiers</region> <city>Skikda</city> </row> <row> <country>American Samoa</country> <region/> <city>Pago Pago</city> </row> </rowset> Thanks Priya Sincerely, Priya Ann Pinto Software Engineer - Java Email : Priya.P@xxxxxxx ___________________________________________________________________ ITCC FZ L.L.C P.O. Box 74500 Dubai, United Arab Emirates Phone : +971 4 330 3778 Fax : +971 4 330 3779 Website : http://www.ITCC.ws This message and any attachments are confidential to the ordinary user of the email address to which it is addressed and may also be legally privileged. If you are not the intended recipient, the printing, copying, forwarding, disclosure, or use of any part of this message or its attachments is strictly prohibited, and may be unlawful. If you have received this message in error, please inform the sender immediately by return e-mail and then promptly delete it from your system. We strongly recommend that you read the complete version of this confidentiality note and disclaimer, available on our website at http://www.ITCC.ws/email_disclaimer.html XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Need Book/Resources on Xalan , Sudhir Malhotra | Thread | Re: [xsl] Check for null value and , Jeni Tennison |
[xsl] Need Book/Resources on Xalan , Sudhir Malhotra | Date | [xsl] <xsl:for-each select> and ace, Priya Pinto |
Month |