473,386 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

XSL Query

I want to genereate a csv file form an XML as shown below, and the content
of csv are as follows
<DATE>,<first ATOM/NAME>,<second ATOM/NAME>

I am able to select first and the second NAME element, but the problem is
that when number of instances of <NAME> is<2 I want the output to be
<DATE>,, (at least two comma)
But since the elements are not present so the rule does not execute and i
don't get any comma in the output.csv

Please suggest what should be done.

The files i used are as follows.

*************** Input XML
<?xml version="1.0"?>
<?xml-stylesheet type="text/xml" href="xml.xsl"?>
<PERIODIC_TABLE>
<DATE>12/29/2005</DATE>

<ATOMS>
<NAME>Hydrogen</NAME>
</ATOMS>

<ATOMS>
<NAME>Helium</NAME>
<NAME>Neon</NAME>
</ATOMS>

<ATOMS>
<NAME>Carbon</NAME>
<NAME>Oxygen</NAME>
<NAME>Copper</NAME>
<NAME>Iron</NAME>
<NAME>Argon</NAME>
</ATOMS>

<ATOMS></ATOMS>

</PERIODIC_TABLE>

********************* The XSL

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="PERIODIC_TABLE">
<xsl:apply-templates select="ATOMS"/>
</xsl:template>

<xsl:template match="ATOMS">
<xsl:apply-templates select="NAME"/><xsl:text>&#xa;</xsl:text>
</xsl:template>

<xsl:template match="NAME">
<xsl:if test="position()&lt;3"><xsl:value-of select="self::NAME"/>,</xsl:if>
</xsl:template>

</xsl:stylesheet>
Dec 29 '05 #1
1 1106
Sandy wrote:
But since the elements are not present so the rule does not execute and i
don't get any comma in the output.csv
Are you sure that XSL is the right tool for this ?
Please suggest what should be done.


Try other tools, like XMLgawk.
I bet you can solve your problem in 10 lines of source code.
Dec 29 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the...
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
3
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says...
14
by: Dave Thomas | last post by:
If I have a table set up like this: Name | VARCHAR Email | VARCHAR Age | TINYINT | NULL (Default: NULL) And I want the user to enter his or her name, email, and age - but AGE is optional. ...
1
by: giovannino | last post by:
Dear all, I did a query which update a sequence number (column NR_SEQUENZA) in a table using a nice code (from Trevor !). 1) Given that I'm not a programmer I can't understand why...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.