On 3 February 2010 04:11, ac <ac(_at_)hyperbase(_dot_)com> 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/
--~------------------------------------------------------------------
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>
--~--