Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSL Query

Reply
Thread Tools

XSL Query

 
 
Sandy
Guest
Posts: n/a
 
      12-29-2005
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"
xmlnssl="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>


 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?J=FCrgen_Kahrs?=
Guest
Posts: n/a
 
      12-29-2005
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
tomcal/xsl - problems with xsl:include Klaus Friese Java 0 11-22-2004 10:17 AM
XSL-1000: (Fatal Error) Error while parsing XSL file (org.apache.xerces.parsers.AbstractSAXParser$AttributesProxy) Kevin Flood Java 1 09-13-2004 02:28 PM
XSL-1000: (Fatal Error) Error while parsing XSL file (org.apache.xerces.parsers.AbstractSAXParser$AttributesProxy) Kevin Flood Java 0 09-08-2004 02:11 PM
use xsl:element to output an "<xsl:template match=...> ? Ray Tayek XML 3 11-30-2003 10:14 AM



Advertisments