xsl-list
[Top] [All Lists]

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

2006-06-21 13:26:35
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(_at_)mulberrytech(_dot_)com]
Sent: Wednesday, June 21, 2006 1:02 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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.


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