RE: [xsl] Converting CSV to XML without hardcoding schema details in xsl

Subject: RE: [xsl] Converting CSV to XML without hardcoding schema details in xsl
From: "Pantvaidya, Vishwajit" <vpantvai@xxxxxxxxxxxxx>
Date: Wed, 21 Jun 2006 13:26:09 -0700
You are correct, Wendell. I am using XSLT2.0.

Other than breaking up the strings, my issue is how to generate the output
xml with the element names generated at runtime from the field names in the
csv.

I was using xsl:element - but I was trying to achieve the above using
item-at and was not sure if I can use that function within the xsl:element
name AVT.

Thanks a lot,

Vish.
>-----Original Message-----
>From: Wendell Piez [mailto:wapiez@xxxxxxxxxxxxxxxx]
>Sent: Wednesday, June 21, 2006 1:02 PM
>To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>Subject: RE: [xsl] Converting CSV to XML without hardcoding schema details
>in xsl
>
>Hi Vish,
>
>I take it you're using XSLT 2.0 from the construct for-each
>select="tokenize(.,',')"?
>
>If not, let's not get on the wrong track.
>
>Even if so, look up the instruction <xsl:element/>, since it'll allow
>you to create elements named with values from your data -- better
>than trying to write tags. Thus their names don't have to be hard-coded.
>
>As for how to break your values out, that depends on whether you're
>using XSLT 2.0, which has better facilities for this, or 1.0, which
>requires you to break up the strings recursively (or use extension
>functions).
>
>Answer the 1.0/2.0 question and someone can help further. (I think I
>may be done for the day, sorry.)
>
>Cheers,
>Wendell
>
>At 03:17 PM 6/21/2006, you wrote:
>>Can anybody suggest how to convert CSV data in the format
>>
>>Field1,Field2
>>Value11,Value12
>>
>>to xml like
>>
>><Field1>Value11</Field1>
>><Field2>Value12</Field2>
>>
>>without hardcoding the fieldnames in the xsl?
>>
>>I was thinking of something like
>>
>><xsl:for-each select="tokenize(., ',')">
>>&lt;<xsl:value-of select="item-at($elementNames,index-of(?parent of
>current
>>node?,.))"/>&gt;
>><xsl:value-of select="."/>
>>&lt;/<xsl:value-of select="item-at($elementNames,index-of(?parent of
>current
>>node?,.))"/>&gt;
>></xsl:for-each>
>>
>>where elementNames is a tokenized list of the fieldnames - but I am unable
>>to get it to work.

Current Thread