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

Check for null value and Check if child tag exists

Subject: 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
xsl if child
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

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-2013 All Rights Reserved.