Convert a flat file to XML using XSLT technology

I am developing a system that receives data from several partners in the form of CSV files. Files may differ in the number and order of columns. For the most part, I want to select a subset of the columns, perhaps reorder them and pass them to the parser. Obviously, I would prefer to be able to convert the input to some canonical format to make the parser as simple as possible.

Ideally, I would like to be able to generate a conversion for each input data format using some graphical tool and save the conversion as a document in a database or on disk. After receiving the data, I would apply the correct transformation (no matter how I define the correct transformation) to get the XML document in canonical format. If the input files contained XML, I would just create an XSLT document for each format and be on my way.

I used BizTalk Flat File XSLT extensions (or something else that they called) for something similar in the past, but I don’t want this project to have any problems with BizTalk (and I also can’t afford it) .

Does anyone know if there are alternative XSLT technologies and / or extensions that would allow me to achieve my goal in an elegant way?

I am developing my application in C # on .NET 3.5 SP1 (therefore I prefer the technologies supported by .NET).

+1
source share
8 answers

XSLT provides new features that simplify the analysis of non-XML files.

Andrew Welch publishes an XSLT 2.0 example that converts CSV to XML

+1
source

I think you need something like this (sorry, .NET is not supported, but the code is very simple)

http://csv2xml.sourceforge.net

0
source

IIRC - "LINQ to CSV", XML ( ) .

.

0

2 .

Progress Software API (.Net), .conv(flat to XML converter), Stylus Studio, XML . : http://www.datadirect.com/developer/data-integration/tutorials/converter-sample-code/index.ssp

, XML-, XFLAT, , , .. java, , XFLAT XML, XML XML XSLT. : http://www.unidex.com/overview.htm

, .

0

LINQ to CSV. Microsoft , - Matt Perdeck. ...

0

XmlReader, -XML-. , , XSLT- , XSLT.

0

linux ip route list. , .

, "output", . tokenize xpath 2.0. , . , , . Id spli ','

<?xml version="1.0" encoding="UTF-8"?>

<xsl:output method="xml" indent="yes" />

<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
</xsl:template>

<xsl:template match="//output">
    <!-- split things up for each new line -->
    <xsl:variable name="line" select="tokenize(.,'\n')"/>
    <xsl:for-each select="$line">                        
        <!-- split each line into peices based on space -->
        <xsl:variable name="split" select="tokenize(.,' +')"/>
        <xsl:if test="count($split) &gt; 1">
            <xsl:element name="route">                                        
                <xsl:for-each select="$split">
                    <xsl:choose>
                        <xsl:when test="position() = 1">
                            <xsl:attribute name="address" select="."/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:variable name="index" select="position()"/>
                            <xsl:variable name="fieldName" select="."/>
                            <xsl:if test="$fieldName and position() mod 2 = 0">
                                <xsl:attribute name="{$fieldName}" select="$split[$index + 1]"/>
                            </xsl:if>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:for-each>
            </xsl:element>
        </xsl:if>
    </xsl:for-each>
</xsl:template>

0

You can also take a look at altova MapForce

-1
source

All Articles