Page 1 of 1
Converting Pipe-Delimited txt to XML
Posted: Thu Mar 30, 2006 6:25 pm
by diblassio4
Hi George, (and everyone else!)
I checked out
http://www.oxygenxml.com/forum/ftopic977.html and
I was trying to use the nice example you posted, but using <xsl:analyze-string select="$value" regex="\|"> for pipe-delimited instead.
The problem comes when there is an empty field like such:
field|secondfield|||fifthField (fields 3 and 4 are empty)
field||thirdfield||fifthField (fields 2 and 4 are empty)
then the positions get janked out of consistency in the results...
Any ideas?
Thanks in advance!
Posted: Mon Apr 03, 2006 8:48 am
by Radu
Hi,
Sorry for the delay.
If you check the annotation of the "xsl:analyse" tag available in the Model View it says something like:
Code: Select all
...Each substring will contain at least one character.
so this means you will not be notified in the "xsl:non-matching-substring" of empty strings.
I found an interesting XSLT 2.0 method called "tokenize" that seems to do exactly the same thing
http://www.w3.org/TR/xpath-functions/#func-tokenize but also return the 0-length matches between the separators.
Sample usage:
Code: Select all
<xsl:variable name="var"
select="tokenize('field|secondfield|||fifthField', '\|')"/>
<xsl:for-each select="$var">
<entry>
<xsl:value-of select="."/>
</entry>
</xsl:for-each>
The code above will also output empty "entry" tags when there is no content between separators.
Hope this helps,
Regards, Radu.
Posted: Thu Sep 20, 2007 1:42 pm
by ravi
Hi Radhu,
am new to this site and as well as am new to the XSLT, i need a help regarding converting CSV file to XML file
here am getting the CSV file from the MQ Queue, the message looks like this
<payload>abc,111,india</payload>
i would like to conver this MQ message into the XML message using the XSLT
expected out should like this :
<?xml version="1.0" encoding="UTF-8"?>
<empdetails><empname>abc</empname><empid>111</empid><empcountry>india<empcountry></empdetails>
it would be a gr8 if you could provide me the XSLT for this,
thanks in advance
Posted: Thu Sep 20, 2007 10:49 pm
by jkmyoung
<xsl:variable name="var" select="tokenize('payload', ',|')"/>
Posted: Thu Sep 20, 2007 10:49 pm
by jkmyoung
Cursed no edit forum.
<xsl:variable name="var" select="tokenize('payload', ',')"/>
Posted: Fri Sep 21, 2007 12:35 pm
by ravi
jkmyoung wrote:Cursed no edit forum.
<xsl:variable name="var" select="tokenize('payload', ',')"/>
am totally new to XSL, if you could provide me the XSL it's great, and also please remeber i need the each coloum in seperate tag
like if the input record is like this : ajay,111,india,1000
then am expecting the ajay in <empname>ajay</empname> tag, <empid>111</empid><empcountry>india</empcountry><empsal>1000</empsal>
am expecting the output in the a bove format
thanks in advance