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: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 21 Jun 2006 16:01:56 -0400
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