Hello,
I have a little problem. I have 3 files in a same directory: EtabCsvToXml.xpl, csv2xml.xsl and listEtablissement.csv . I want convert a .csv file in a .xml file with the csv2xml.xsl. I use a file that i found on the net. But when I test, The xsl. file say " Cannot locate : listEtablissement.csv " First, I think, there is a problem with the URI but i don't see the problem. And i want a relative uri... Second, perhaps it's a problem with the Xpath function "unparsed-text-available"... thanks for the help, Fabien This is the 2 principal files: csv2xml.xsl (not complete): <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="fn" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0" exclude-result-prefixes="xs fn"> <xsl:output indent="yes" encoding="US-ASCII" /> <xsl:param name="pathToCSV" select="'listEtablissement.csv'" /> <xsl:template match="/" name="main"> <xsl:choose> <xsl:when test="unparsed-text-available($pathToCSV)"> <root> ... </root> </xsl:when> <xsl:otherwise> <root> <xsl:text>Cannot locate : </xsl:text><xsl:value-of select="$pathToCSV" /> </root> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> EtabCsvToXml.xpl: <p:pipeline xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:oxf="http://www.orbeon.com/oxf/processors" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <p:param name="data" type="output" /> <p:processor name="oxf:xslt"> <p:input name="data"><dummy/></p:input> <p:input name="config"> <xsl:stylesheet version="2.0"> <xsl:import href="csv2xml.xsl" /> </xsl:stylesheet> </p:input> <p:output name="data" ref="data" /> </p:processor> </p:pipeline> -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws |
-- -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws |
Hi Fabien,
If you happen to figure this out, please post an update to the list because I can imagine needing to import CSV into an application in the future. Thanks, Ethan On Tue, Mar 2, 2010 at 3:27 PM, Louis Ratzesberger <[hidden email]> wrote:
-- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws |
Hello,
I follow the instructions of Hank and it's now Ok. I paste all my file. I hope help an other guy. :-) Fabien. The .csv file: RNE Ville Nom 0670076U SOUFFLENHEIM COLLEGE ALBERT CAMUS 0680128V SOULTZ-HAUT-RHIN COLLEGE ROBERT BELTZ 0671827X SOULTZ-SOUS-FORETS COLLEGE DE L'OUTRE FORET 0670105A STRASBOURG COLLEGE LEZAY MARNESIA 0670133F STRASBOURG COLLEGE KLEBER 0671508A STRASBOURG COLLEGE JACQUES TWINGER 0671590P STRASBOURG COLLEGE SOPHIE GERMAIN 0671593T STRASBOURG COLLEGE LOUISE WEISS 0671594U STRASBOURG COLLEGE ROBERTSAU 0671691Z STRASBOURG COLLEGE STOCKFELD The XPL file: <p:pipeline xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:oxf="http://www.orbeon.com/oxf/processors" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <p:param name="instance" type="input" /> <p:param name="data" type="output" /> <!-- Upload of .csv --> <p:processor name="oxf:url-generator"> <p:input name="config"> <config> <url>listEtablissement.csv</url> <content-type>text/plain</content-type> </config> </p:input> <p:output name="data" id="documentTexteCsv" /> </p:processor> <p:processor name="oxf:xslt"> <p:input name="data" href="#documentTexteCsv"/> <p:input name="config"> <xsl:stylesheet version="2.0"> <xsl:import href="XSL/csv2xml-xslt2.xsl" /> </xsl:stylesheet> </p:input> <p:output name="data" id="csvConverti" ref="data"/> </p:processor> </p:pipeline> The csv2xml-xslt2.xsl : (The original source is here: http://andrewjwelch.com/code/xslt/csv/csv-to-xml_v2.html#instructions) <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="fn" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0" exclude-result-prefixes="xs fn"> <xsl:output indent="yes" encoding="US-ASCII" /> <xsl:function name="fn:getTokens" as="xs:string+"> <xsl:param name="str" as="xs:string" /> <xsl:analyze-string select="concat($str, ',')" regex='(("[^"]*")+|[^,]*),'> <xsl:matching-substring> <xsl:sequence select='replace(regex-group(1), "^""|""$|("")""", "$1")' /> </xsl:matching-substring> </xsl:analyze-string> </xsl:function> <xsl:template match="/" name="main"> <xsl:choose> <xsl:when test="/document"> <xsl:variable name="csv" select="/document"/> <xsl:variable name="lines" select="tokenize($csv, '\n')" as="xs:string+" /> <xsl:variable name="elemNames" select="fn:getTokens($lines[1])" as="xs:string+" /> <root> <xsl:for-each select="$lines[position() > 1]"> <row> <xsl:variable name="lineItems" select="fn:getTokens(.)" as="xs:string+" /> <xsl:for-each select="$elemNames"> <xsl:variable name="pos" select="position()" /> <elem name="{.}"> <xsl:value-of select="$lineItems[$pos]" /> </elem> </xsl:for-each> </row> </xsl:for-each> </root> </xsl:when> </xsl:choose> </xsl:template> </xsl:stylesheet> The CSV convert to XML: <root> <row> <elem name="RNE">0670076U</elem> <elem name="Ville">SOUFFLENHEIM</elem> <elem name="Nom">COLLEGE ALBERT CAMUS</elem> </row> <row> <elem name="RNE">0680128V</elem> <elem name="Ville">SOULTZ-HAUT-RHIN</elem> <elem name="Nom">COLLEGE ROBERT BELTZ</elem> </row> <row> <elem name="RNE">0671827X</elem> <elem name="Ville">SOULTZ-SOUS-FORETS</elem> <elem name="Nom">COLLEGE DE L'OUTRE FORET</elem> </row> ... </root> Ethan Gruber a écrit : > Hi Fabien, > > If you happen to figure this out, please post an update to the list > because I can imagine needing to import CSV into an application in the > future. > > Thanks, > Ethan > > On Tue, Mar 2, 2010 at 3:27 PM, Louis Ratzesberger > <[hidden email] <mailto:[hidden email]>> wrote: > > > Hi Fabian, > > While I cannot address your XSLT issue, I think there is a > way to get your data into the stylesheet within XPL. > > You can load your file with the url-generator in text mode: > > http://www.orbeon.com/orbeon/doc/processors-generators-url#text-mode > > And then use it as a user-defined input to xslt: > > http://www.orbeon.com/orbeon/doc/processors-xslt#user-defined > > Your document will be wrapped in a "document" element: > > <document xsi:type="xs:string" > content-type="text/plain">....</document> > > Regards, > Hank > > > > > Quoting Fabien GUENEGO <[hidden email] > <mailto:[hidden email]>>: > > > Hello, > > I have a little problem. > > I have 3 files in a same directory: EtabCsvToXml.xpl, > csv2xml.xsl and > > listEtablissement.csv . > > I want convert a .csv file in a .xml file with the csv2xml.xsl. > I use > > a file that i found on the net. But when I test, The xsl. file say " > > Cannot locate : listEtablissement.csv " > > > > First, I think, there is a problem with the URI but i don't see the > > problem. And i want a relative uri... Second, perhaps it's a > problem > > with the Xpath function "unparsed-text-available"... > > > > thanks for the help, > > > > Fabien > > > > > > This is the 2 principal files: > > > > csv2xml.xsl (not complete): > > > > <?xml version="1.0" encoding="ISO-8859-1"?> > > <xsl:stylesheet > > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > > xmlns:fn="fn" > > xmlns:xs="http://www.w3.org/2001/XMLSchema" > > version="2.0" exclude-result-prefixes="xs fn"> > > > > <xsl:output indent="yes" encoding="US-ASCII" /> > > > > <xsl:param name="pathToCSV" select="'listEtablissement.csv'" /> > > > > <xsl:template match="/" name="main"> > > <xsl:choose> > > <xsl:when test="unparsed-text-available($pathToCSV)"> > > <root> > > ... > > </root> > > </xsl:when> > > <xsl:otherwise> > > <root> <xsl:text>Cannot locate : </xsl:text><xsl:value-of > > select="$pathToCSV" /> > > </root> > > </xsl:otherwise> > > </xsl:choose> > > > > </xsl:template> > > > > </xsl:stylesheet> > > > > EtabCsvToXml.xpl: > > > > <p:pipeline xmlns:p="http://www.orbeon.com/oxf/pipeline" > > xmlns:oxf="http://www.orbeon.com/oxf/processors" > > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > > > > <p:param name="data" type="output" /> > > > > <p:processor name="oxf:xslt"> > > <p:input name="data"><dummy/></p:input> > > <p:input name="config"> > > <xsl:stylesheet version="2.0"> > > <xsl:import href="csv2xml.xsl" /> > > </xsl:stylesheet> > > </p:input> > > <p:output name="data" ref="data" /> > > </p:processor> > > > > </p:pipeline> > > > > > > -- > Hank Ratzesberger > [hidden email] <mailto:[hidden email]> > > > > -- > You receive this message as a subscriber of the [hidden email] > <mailto:[hidden email]> mailing list. > To unsubscribe: mailto:[hidden email] > <mailto:[hidden email]> > For general help: mailto:[hidden email] > <mailto:[hidden email]>?subject=help > OW2 mailing lists service home page: http://www.ow2.org/wws > > -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws |
Thanks!
On Fri, Mar 5, 2010 at 2:05 PM, Fabien GUENEGO <[hidden email]> wrote: Hello, -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws |
Free forum by Nabble | Edit this page |