xsl-list
[Top] [All Lists]

Re: [xsl] csv data to xml

2013-06-28 03:28:40

On 28 Jun 2013, at 06:10, henry human wrote:



Michael
In a servlet I am calling the saxon parser (v. 9) and as input for the parser 
put a string that contains the csv data. I do not work wih files or fiel 
references therfore cant call the xslt as it is with the referenced files..

If the stylesheet is calling the unparsed-text() function then the simplest way 
to use it without change would be to register an UnparsedTextResolver, which 
responds to the request for a particular URI by returning a StringReader for 
the resulting text.

Alternatively, it would be very easy to modify the stylesheet to reference a 
stylesheet parameter instead of calling unparsed-text().

Michael Kay
Saxonica


brg
henry 
----- Ursprüngliche Message -----
Von: Michael Kay <mike(_at_)saxonica(_dot_)com>
An: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
CC: 
Gesendet: 18:26 Donnerstag, 27.Juni 2013
Betreff: Re: [xsl] csv data to xml

If you could be more precise about how you were trying "to rund the XSLT not 
localy", and what problem you encountered when doing so, and what you were 
trying to achieve, then we might be able to help you.

Michael Kay
Saxonica

On 27 Jun 2013, at 17:14, henry human wrote:

I had some problem to rund the XSLT not localy and working with files but 
with on  Web server and working with string.
So I used some java based code and build the xml! 
Could you tell mme how to modify the XSLT to be able call it on server(I 
removed the CSV file reference but did not work? 
brg
henry


----- Ursprüngliche Message -----
Von: Andrew Welch <andrew(_dot_)j(_dot_)welch(_at_)gmail(_dot_)com>
An: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
CC: 
Gesendet: 17:39 Donnerstag, 27.Juni 2013
Betreff: Re: [xsl] csv data to xml

You appear to have changed the output from the xslt I linked to?  You
should have rows wrapping your elements, once you reinstate them then
how to achieve the 2nd part of your process becomes clearer.


On 27 June 2013 16:28, henry human <henry_human(_at_)yahoo(_dot_)de> wrote:
Hi guys
I was able to convert the data from csv to xml. Now I want to build groups 
of the elements such as the sample bellow.
Each 5 elements should be assigned to a clfPackage element:

This is the CSV as xml:
<?xml version="1.0" encoding="UTF-8"?>
<xmlData>
  <element>EN</element>
  <element>01</element>
  <element>text</element>
  <element>U</element>
  <element>2013028074426</element>

  <element>SE</element>
  <element>06</element>
  <element>text</element>
  <element>M</element>
  <element>2013011234457</element>

  .......

</xmlData>

This is what must be created:
  <clfPackage>
  <Country><xsl:value-of select="xmlData/element"/></CountryCode>          
//must be the first element
  <number><xsl:value-of select="xmlData/element"/></ClearingNumber>        
//must be the secound element
  <Description1><xsl:value-of select="xmlData/element"/></Description>
  <ChangeMode><xsl:value-of select="xmlData/element"/></ChangeMode>
  <Modification><xsl:value-of select="xmlData/element"/></Modification>
  </clfPackage>

Best regards
Henry




----- Ursprüngliche Message -----
Von: Michael Kay <mike(_at_)saxonica(_dot_)com>
An: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
CC:
Gesendet: 16:47 Mittwoch, 26.Juni 2013
Betreff: Re: [xsl] csv data to xml


On 26 Jun 2013, at 15:21, henry human wrote:

Hi I was not able to run get this xslt sample runing! When I try it with 
Saxon 9.1.0  and (call it in Stylus Studio) I got the known
error:ontent is not allowed in prolog.

That means you're doing it wrong; you're somehow putting the CSV file 
through an XML parser. Probably because you are supplying it as the main 
input to the transformation, rather than merely a secondary file to be read 
with unparsed-text().

Michael Kay
Saxonica


?
This was my csv file test.csv
USA,AA,Comp. 1,U,012345,L987
USA,BB,Comp.2,Z,034567888888,F098
USA,CC,Comp 3,M,034847474747,F098


----- Ursprüngliche Message -----
Von: Andrew Welch <andrew(_dot_)j(_dot_)welch(_at_)gmail(_dot_)com>
An: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
CC:
Gesendet: 15:15 Dienstag, 25.Juni 2013
Betreff: Re: [xsl] csv data to xml

Use unparsed-text() to read the csv, then use tokenize() to split it
into lines, iterate over each line outputting a <Segment>, then
tokenize() the $line into $tokens, and use fill-in-the-blanks style to
populate the elements.

Basically this:

http://andrewjwelch.com/code/xslt/csv/csv-to-xml_v2.html


--
Andrew Welch
http://andrewjwelch.com/

--~------------------------------------------------------------------
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>
--~--

--~------------------------------------------------------------------
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>
--~--



--~------------------------------------------------------------------
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>
--~--


--~------------------------------------------------------------------
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>
--~--




-- 
Andrew Welch
http://andrewjwelch.com/

--~------------------------------------------------------------------
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>
--~--


--~------------------------------------------------------------------
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>
--~--



--~------------------------------------------------------------------
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>
--~--


--~------------------------------------------------------------------
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>
--~--



--~------------------------------------------------------------------
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>
--~--


<Prev in Thread] Current Thread [Next in Thread>