xsl-list
[Top] [All Lists]

RE: write text using XSLT

2005-08-19 08:21:26
Praveenjothi,

The header row is being output with each data row. You want to separate
them. A stylesheet like the following might do what you need:

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

<xsl:output method="text"/>

<xsl:template match="/">
        <xsl:text>product_number,product,quantity,size</xsl:text>
        <xsl:text>&#10;</xsl:text>
        <xsl:apply-templates select="row-element"/>
</xsl:template>

<xsl:template match="row-element">
        <xsl:value-of select="description/@product_number"/>
        <xsl:text>,</xsl:text>
        <xsl:value-of select="description"/>
        <xsl:text>,</xsl:text>
        <xsl:value-of select="quantity"/>
        <xsl:text>,</xsl:text>
        <xsl:value-of select="size"/>
        <xsl:text>&#10;</xsl:text>
</xsl:template>

</xsl:stylesheet>

presume your xml is like:

<data>
        <row-element>
                <description product_number="a">
                        some text
                </description>
                <quantity>20</quantity>
                <size>20</size>
        </row-element>
</data>

I did not test this sample. Hope this helps.

Douglas Ross 
Senior Software Engineer, Advanced Development 
Kronos 
www.kronos.com 
Improving the Performance of People and Business(tm) by making software
Smaller, Faster, Sharper, Easier 


-----Original Message-----
From: Praveenjothi Paranjothi [mailto:praveen_eu(_at_)yahoo(_dot_)com] 
Sent: Friday, August 19, 2005 11:05 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] write text using XSLT 

Dear all,
 
I am new to XML and XSLT. My task is to convert a XML
file to CSV format. I have finished matching the
elements and retrieving the data and writing as comma
separated values. This data is basically from a
Database and unfortunately the XML file does not
contain the column names of the datas. I would like to
write the column names of the data in XSLT so that it
can be printed in the CSV file.
 
I would like to know how to print a text once in the
CSV format using XSLT. I want to write the column
names in the XSLT file so that when I convert it to a
CSV file I see the column names once and the datas in
many rows below them.
 

<?xml version="1.0"?>
<xsl:stylesheet version = "1.0"
    xmlns:xsl =
"http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="text"/>
product_number,product,quantity,size
<xsl:value-of
select="description/@product_number"/>,<xsl:value-of
select="description"/>,<xsl:value-of
select="quantity"/>,<xsl:value-of select="size"/>
<xsl:text>&#10;</xsl:text>
</xsl:template>
</xsl:stylesheet>


In the above stylesheet I want
product_number,product_id,quantity,size to be written
into the text format only once. But for each product
row I get the above names written. Kindly suggest me
how to solve the above problem.


Any help in this regard is greatly appreciated and
thank you very much.
 
Regards,
Praveen


                
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>