ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sean Tiley" <sti...@meraksystems.com>
Subject RE: csv to html via xslt or xslt2 task ?
Date Tue, 11 Mar 2008 15:21:41 GMT
Hi there,
I am new to XSLT but saw your post and decided to attempt a solution,
mainly as an exercise for myself.

The responses you have received have better solutions than this one, but
I offer a novice's solution, which is neither elegant or flexible


(sorry for the formatting)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
    <xsl:output indent="yes"/>
    <!-- file location-->
    <xsl:variable name="in" 
 
select="unparsed-text('file:///c:/sean/xsl/commadelimited/comma_delimite
d.txt')"/>
    <xsl:template name="initial" match="/">
        <xsl:element name="values">
            <!-- Iterate through the lines in the file -->
            <xsl:for-each select="tokenize($in,'\r\n')">
                <xsl:variable name="line" select="."/>
                <!-- 
                    Analyze the entire line and break into captured
groups 
                    (by using ( ) around the individual pieces  
                -->
                <xsl:analyze-string select="$line"
 
regex="([0-9]+),\s*([0-9]+),\s*([A-Z]+),\s*([0-9]+),\s*([A-Z]+),\s*([A-Z
])+,s*([A-Z]+),\s*([A-Z]+)">
                    <xsl:matching-substring>
                        <xsl:element name="line">
                            <!--  
                             This just puts out the line, was included
for testing purposed
                            <xsl:element name="RawData">
                              <xsl:value-of select="regex-group(0)"/>
                            </xsl:element>
                            -->
                            <xsl:element name="Column1">
                                <xsl:value-of select="regex-group(1)"/>
                            </xsl:element>
                            <xsl:element name="Column2">
                                <xsl:value-of select="regex-group(2)"/>
                            </xsl:element>
                            <xsl:element name="Column3">
                                <xsl:value-of select="regex-group(3)"/>
                            </xsl:element>
                            <xsl:element name="Column4">
                                <xsl:value-of select="regex-group(4)"/>
                            </xsl:element>
                            <xsl:element name="Column5">
                                <xsl:value-of select="regex-group(5)"/>
                            </xsl:element>
                            <xsl:element name="Column6">
                                <xsl:value-of select="regex-group(6)"/>
                            </xsl:element>
                            <xsl:element name="Column7">
                                <xsl:value-of select="regex-group(7)"/>
                            </xsl:element>
                            <xsl:element name="Column8">
                                <xsl:value-of select="regex-group(8)"/>
                            </xsl:element>
                        </xsl:element>
                    </xsl:matching-substring>
                    <xsl:non-matching-substring>
                        <xsl:element name="UnmatchedInputLines">
                            <xsl:value-of select="."/>
                        </xsl:element>    
                    </xsl:non-matching-substring>
                </xsl:analyze-string>
            </xsl:for-each>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

 
-----Original Message-----
From: Z W [mailto:mpc8250@gmail.com] 
Sent: Thursday, March 06, 2008 6:17 PM
To: Ant Users List
Subject: csv to html via xslt or xslt2 task ?

Hi ppl,

I have a few rows of comma delimited csv file.


1204823515990,2091,Cl,200,OK,M,text,true

1204823518623,828,Su,200,OK,M,text,true

1204823519500,66,Se,200,OK,M,text,true

1204823519604,42,Se,OK,M,text,true

and I like to transform it into html with xslt or xslt2.  Is that
possible ?

Could someone provide a simple example to manipulate 2 field in a
stylesheet
? I'm new to this hence

such a question.

Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message