CSV / Text files

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

CSV / Text files

joac

Hi,

 

Is there a processor to convert CSV to XML? Or process CVS and TXT files?

 

Thanks,

Jordi



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: CSV / Text files

Alexander Žaťko
If you want to convert just a handful of files then a decent XML editor should allow you to open delimited text files and convert them into XML (Oxygen does). If you want to create an app to do conversion on regular basis, then you can create an XSLT stylesheet and have OF do it.

A.


On Feb 9, 2007, at 11:10 AM, Jordi Amatller wrote:

Hi,

 

Is there a processor to convert CSV to XML? Or process CVS and TXT files?

 

Thanks,

Jordi


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: [hidden email]
For general help: [hidden email]
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: CSV / Text files

Martin Mohnhaupt
Hello,

I have a piece XSL of code to do CSV -> XML.
Here it is :-)

The data is then further processed with an oxf:xslt processor.



Alexander Zatko wrote:
If you want to convert just a handful of files then a decent XML editor should allow you to open delimited text files and convert them into XML (Oxygen does). If you want to create an app to do conversion on regular basis, then you can create an XSLT stylesheet and have OF do it.

A.


On Feb 9, 2007, at 11:10 AM, Jordi Amatller wrote:

Hi,

 

Is there a processor to convert CSV to XML? Or process CVS and TXT files?

 

Thanks,

Jordi


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: [hidden email]
For general help: [hidden email]
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws


-- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: [hidden email] For general help: [hidden email] ObjectWeb mailing lists service home page: http://www.objectweb.org/wws

-- 
Martin Mohnhaupt
Nice Data Systems
Rue de Lyon 42 - CH 1203 GENEVE
Tél: +41 (0) 22 344 11 39
Mob: +41 (0) 78 636 00 75
Email: [hidden email]
Web: http://www.nicedata.com
Skype: martin.mohnhaupt
Action Carbone: http://www.actioncarbone.org

<?xml version="1.0" encoding="iso-8859-1"?>
<!--
    Copyright (C) 2006 Nice Data Systems, http://www.nicedata.com

    File:      csv2xml.xsl
    Project:   Information Exchange Platform
    Owner:     IT department
    Purpose:   Convert Excel CSV files to XML
    Created:   20oct2006
    Remark:
 -->
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:cll="http://www.nicedata.com/ns/object"
    xmlns:ds="http://www.nicedata.com/ns/ds">
   
    <xsl:output method="text" encoding="iso-8859-1"/>
   
    <!-- Parameters and constants -->
    <xsl:param name="eol" select="'&#x0A;'"/>  
    <xsl:param name="now" select="current-dateTime()"/>  
    <xsl:param name="uri" select="static-base-uri()"/>  
   

    <!--
         Perform some string cosmetics
         Place some spaces around the separators
    -->  
    <xsl:param name="csv-data">
        <ds:document>
            <xsl:value-of select="replace(., ';', ' ; ')"/>
         </ds:document>
    </xsl:param>
   
    <!--
         main template
    -->
    <xsl:template match="/">
        <xsl:element name="cll:object">
            <xsl:attribute name="type">data</xsl:attribute>
            <xsl:value-of select="$eol"/>
            <xsl:element name="cll:header">
                <xsl:value-of select="$eol"/>
                <xsl:element name="cll:stamp">
                    <xsl:value-of select="$now"/>
                </xsl:element>
                <xsl:value-of select="$eol"/>
                <xsl:element name="cll:generated-by">
                    <xsl:value-of select="$uri"/>
                </xsl:element>
                <xsl:value-of select="$eol"/>
            </xsl:element>
            <xsl:value-of select="$eol"/>
            <xsl:element name="cll:payload">
                <xsl:attribute name="type">dataset</xsl:attribute>
                <xsl:value-of select="$eol"/>
                <xsl:element name="ds:dataset">
                    <xsl:call-template name="rows">
                        <xsl:with-param name="value" select="$csv-data"/>
                    </xsl:call-template>
                </xsl:element>
                <xsl:value-of select="$eol"/>
            </xsl:element>
            <xsl:value-of select="$eol"/>
        </xsl:element>
        <xsl:value-of select="$eol"/>
    </xsl:template>

    <!--
         Tokenize rows
    -->
    <xsl:template name="rows">
        <xsl:param name="value" select="''"/>
        <xsl:analyze-string select="$value" regex="\n|\r">
            <xsl:matching-substring>
            </xsl:matching-substring>
            <xsl:non-matching-substring>
                <xsl:value-of select="$eol"/>
                <xsl:element name="ds:row">
                    <xsl:value-of select="$eol"/>
                    <xsl:call-template name="columns">
                        <xsl:with-param name="value" select="."/>
                    </xsl:call-template>
                </xsl:element>
                <xsl:value-of select="$eol"/>
            </xsl:non-matching-substring>
        </xsl:analyze-string>
    </xsl:template>

    <!--
         Tokenize columns
    -->
    <xsl:template name="columns">
        <xsl:param name="value" select="''"/>
        <xsl:analyze-string select="$value" regex=";">
            <xsl:matching-substring/>
            <xsl:non-matching-substring>
                <xsl:element name="ds:column">
                    <xsl:value-of select="normalize-space(.)"/>
                </xsl:element>
                <xsl:value-of select="$eol"/>
            </xsl:non-matching-substring>
        </xsl:analyze-string>
    </xsl:template>
</xsl:stylesheet>


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: CSV / Text files

Erik Bruchez
Administrator
In reply to this post by joac
There is no such processor, but you should be able to do the conversion
in XSLT.

-Erik

Jordi Amatller wrote:
> Hi,
>
> Is there a processor to convert CSV to XML? Or process CVS and TXT files?
>
> Thanks,
>
> Jordi

--
Orbeon Forms - Web Forms for the Enterprise Done the Right Way
http://www.orbeon.com/



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws