CSV to XML based on XSD

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<table>
<tbody>
<tr>
<td>
<span>
</td>
<td>


I have a CSV file that needs to be converted to XML based on XSD file. Can I use XSLT for this? If so is there a way to dynamically generate XSLT based on XSD and then do the transformation? I am a newbie to XML and XSLT and trying to find a better way of
doing it. Here is the sample csv. Types other than myrate, abc, xyz, wrap should go into others.

Here is the xsd
<pre>
Code:
<span>    <span><?<span>xml version<span>=<span>"1.0"<span> encoding<span>=<span>"utf-8"<span>?><span><br/><span><<span>xs<span>:<span>schema attributeFormDefault<span>=<span>"unqualified"<span> elementFormDefault<span>=<span>"qualified"<span> xmlns<span>:<span>xs<span>=<span>"http://www.w3.org/2001/XMLSchema"<span>><span><br/>  <span><<span>xs<span>:<span>element name<span>=<span>"Position"<span>><span><br/>    <span><<span>xs<span>:<span>complexType<span>><span><br/>      <span><<span>xs<span>:<span>sequence<span>><span><br/>        <span><<span>xs<span>:<span>element name<span>=<span>"Post"<span> maxOccurs<span>=<span>"unbounded"<span>><span><br/>          <span><<span>xs<span>:<span>complexType<span>><span><br/>            <span><<span>xs<span>:<span>sequence<span>><span><br/>              <span><<span>xs<span>:<span>element name<span>=<span>"rating"<span> maxOccurs<span>=<span>"1"<span> minOccurs<span>=<span>"0"<span>><span><br/>                <span><<span>xs<span>:<span>complexType<span>><span><br/>                  <span><<span>xs<span>:<span>sequence<span>><span><br/>                    <span><<span>xs<span>:<span>element maxOccurs<span>=<span>"unbounded"<span> name<span>=<span>"myrate"<span> minOccurs<span>=<span>"1"<span>><span><br/>                      <span><<span>xs<span>:<span>complexType<span>><span><br/>                        <span><<span>xs<span>:<span>attribute name<span>=<span>"Date"<span> type<span>=<span>"xs:date"<span> use<span>=<span>"required"<span> <span>/><span><br/>                        <span><<span>xs<span>:<span>attribute name<span>=<span>"rate"<span> type<span>=<span>"xs:decimal"<span> use<span>=<span>"required"<span> <span>/><span><br/>                      <span></<span>xs<span>:<span>complexType<span>><span><br/>                    <span></<span>xs<span>:<span>element<span>><span><br/>                  <span></<span>xs<span>:<span>sequence<span>><span><br/>                <span></<span>xs<span>:<span>complexType<span>><span><br/>              <span></<span>xs<span>:<span>element<span>><span><br/>              <span><<span>xs<span>:<span>element name<span>=<span>"Pans"<span> maxOccurs<span>=<span>"unbounded"<span> minOccurs<span>=<span>"1"<span>><span><br/>                <span><<span>xs<span>:<span>complexType<span>><span><br/>                  <span><<span>xs<span>:<span>sequence<span>><span><br/>                    <span><<span>xs<span>:<span>element name<span>=<span>"abcs"<span> maxOccurs<span>=<span>"1"<span> minOccurs<span>=<span>"0"<span>><span><br/>                      <span><<span>xs<span>:<span>complexType<span>><span><br/>                        <span><<span>xs<span>:<span>sequence<span>><span><br/>                          <span><<span>xs<span>:<span>element maxOccurs<span>=<span>"unbounded"<span> name<span>=<span>"abc"<span> minOccurs<span>=<span>"1"<span>><span><br/>                            <span><<span>xs<span>:<span>complexType<span>><span><br/>                              <span><<span>xs<span>:<span>attribute name<span>=<span>"Date"<span> type<span>=<span>"xs:date"<span> use<span>=<span>"required"<span> <span>/><span><br/>                              <span><<span>xs<span>:<span>attribute name<span>=<span>"ID"<span> type<span>=<span>"xs:string"<span> use<span>=<span>"required"<span> <span>/><span><br/>                            <span></<span>xs<span>:<span>complexType<span>><span><br/>                          <span></<span>xs<span>:<span>element<span>><span><br/>                        <span></<span>xs<span>:<span>sequence<span>
[/code]

<pre>
Code:
<span>type<span>,<span>date<span>,<span>id<span>,<span>rate<span>,<span>amt1<span>,<span>amt2<br/>myrate<span>,<span>1<span>/<span>1<span>/<span>2012<span>,<span>5120<span>,<span>0.35<span>,,<span><br/>myrate<span>,<span>1<span>/<span>12<span>/<span>2012<span>,<span>4584<span>,<span>0.21<span>,,<span><br/>abc<span>,<span>1<span>/<span>1<span>/<span>2012<span>,<span>8745<span>,,<span><br/>xyz<span>,<span>12<span>/<span>31<span>/<span>2012<span>,<span>2451<span>,,<span><br/>wrap<span>,<span>8<span>/<span>12<span>/<span>2011<span>,<span>7454<span>,,<span>5421250.12<span>,<span>778545.35<span><br/>wrap<span>,<span>10<span>/<span>12<span>/<span>2011<span>,<span>5454<span>,,<span>48213550.12<span>,<span>4748545.35<span><br/>wen<span>,<span>7<span>/<span>8<span>/<span>2011<span>,<span>521<span>,,,,<span><br/>
[/code]


</td>
</tr>
</tbody>
</table>

View the full article
 
Back
Top