Search

I need to add to a site the functionality of parsing csv's. The csv's look like that (just a snip):

Freitag;13.01.2012;;3,5;;;;;;;; Samstag ;14.01.2012;;;;;;;3,5;;; Freitag;20.01.2012;;;;;;3,5;;;; Samstag;21.01.2012;;;;;3,5;;;;; Freitag;27.01.2012;;;;;;3,5;;;; Samstag;28.01.2012;;;;;;;3,5;;;

I want to parse them on the fly into a HTML table, eg. wrap them in tr's and td's. I've been trying this in various forms for a couple of hours now, the last attempt looked sth like this:

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

I'm kinda desperate by now, anybody any ideas? Thanks in advance!

it may be possible, but you're attempting to leverage symphony into a task that it was not designed for. in this instance, i would suggest straight up php or using kanduvisla's awesome import/export csv extension.

The problem is that these csv's are going to be user uploaded so it needs to be automatized. This is my code so far, last time it did not get through:

    <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template name="replace">
<xsl:variable name="Solution">
<xsl:value-of select="kurs-termine"/>
</xsl:variable>
         <xsl:choose>
          <xsl:when test="contains($Solution, '&#x0A;')">
          <xsl:variable name="textafterbreak" select="substring-after($Solution, '&#x0A;')"/>
           <tr><xsl:value-of select="substring-before($Solution, '&#x0A;')"/></tr><xsl:value-of select="$textafterbreak"/>
          </xsl:when>
          <xsl:when test="contains($Solution, ';')">
          <xsl:variable name="textafterbreak" select="substring-after($Solution, ';')"/>
           <td><xsl:value-of select="substring-before($Solution, ';')"/></td><xsl:value-of select="$textafterbreak"/>
          </xsl:when>
          <xsl:otherwise>
           <xsl:value-of select="$Solution"/>
          </xsl:otherwise>
         </xsl:choose>
        </xsl:template>
</xsl:stylesheet>

I also followed an approach to use str:tokenize for some time, to not much avail. Essentially I "only" need to split the string twice, once at every ";" and then again at all linefills/linebreaks, wrapping the first in td and the second in tr...

Also the imposrt/export csv imports every line as a new entry, thus essentially splitting up the table. I just want to store/process the complete table.

It sounds like this would be better achieved with a CSV Upload field type. It'd work the same as a standard upload field, but shown in a data source you'd do this processing in PHP to convert the CSV into XML. It'd be far easier to do this in PHP since it has more powerful CSV and string manipulation functions.

Thanks for the quick responses. As you might have already guessed I'm not to deep into symphony yet, so I'm in need of a little more direction.

I understand, that I can create custom data sources, I also understand that I can upload the csv via a upload field and then access it through a data source, but where n this path would I be able to modify it with php?

Take a look at Craig's Text Upload field, maybe it could be modified to do what you want with CSV data. The premise of the field is to be able to edit the data with Symphony, or the physical file.

This proved to be the way to go, the csv parsing is kinda quick'n'dirty but for the environment is it intended to be used in it should work. Thanks a lot!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details