|
Subject: Re: [xsl] reading a .xsv file in xslt From: Andrew Welch <andrew.j.welch@xxxxxxxxx> Date: Wed, 3 Feb 2010 08:23:41 +0000 |
On 3 February 2010 04:11, ac <ac@xxxxxxxxxxxxx> wrote:
> Hi,
>
> Andrew, your code is fine but it seems that, to read lines, the line
> <xsl:variable name="lines" select="tokenize($csv, ' ')"
> as="xs:string+" />
> should be more like
> <xsl:variable name="lines" select="tokenize($csv, '\r?\n')"
> as="xs:string+" />
> as there could be spaces in the cells, and as the end-of-line would not be
> recognized anyway.
> What do you think?
That's from it being displayed as html (which i should probably
fix)... if you use the download link to get the file instead then you
can see that it tokenizes on a carriage return:
<xsl:variable name="lines" select="tokenize($csv, '
')" as="xs:string+"/>
> Also, but purely as a matter of taste and case, since all cell values are
> strings, I would tend to use attributes, replacing
> <elem name="{.}">
> <xsl:value-of select="$lineItems[$pos]" />
> </elem>
> with
> <xsl:attribute name="{.}" select="$lineItems[$pos]"/>
See below.....
> Finally, one may also have to handle the case of csv files that do not have
> an initial header line with all valid QName strings.
It can - that's why the name is stored as a name attribute on a
general <elem> element, so that they dont have to be QNames.
> I get a lot of csv files (e.g. from the bank) where the first line is a
> blank line
Use normalize-space on the entire csv text (the string returned from
unparsed-text) then use it again on the column names.
--
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] are all strings in a sequ, Andrew Welch | Thread | Re: [xsl] reading a .xsv file in xs, Wolfgang Laun |
| Re: [xsl] are all strings in a sequ, ac | Date | Re: [xsl] are all strings in a sequ, G. Ken Holman |
| Month |