XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Edward KazanjianSubject: Extract values from XML and convert to CSV using XSLT
Author: Edward Kazanjian
Date: 25 Oct 2004 03:26 PM
Hello,

I would like to extract and tranform xml element values into csv format.

I have attached my source data file and would like to extract data for each fragmentID in csv format.

Could you please step me through the process and show me an example?

Thank you.

Edward


UnknownFragmentModelManualFragment.xml
XML Data Source

Postnext
Ivan PedruzziSubject: Extract values from XML and convert to CSV using XSLT
Author: Ivan Pedruzzi
Date: 25 Oct 2004 05:26 PM
Hi Edward,


Could you be more specific about what would you like to output?
CSV is just a text format to render tabular data.
Which elements would you like to map to which columns?

Here is an example of XSLT that applied to your XML document produces a CSV document, it may be enough to get you started

Hope this helps
Ivan


<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>

<xsl:variable name="separator" select="';'"/>

<xsl:template match="/">
<xsl:value-of select="concat('FragmentId', $separator, 'NPIC50DP', $separator, 'NPIC50EP2', $separator, 'NPSolubility')"/><xsl:text>
</xsl:text>
<xsl:apply-templates select="FragmentModel/Fragment"/>
</xsl:template>

<xsl:template match="Fragment">
<xsl:value-of select="concat(@FragmentId, $separator, NPIC50DP, $separator, NPIC50EP2, $separator, NPSolubility)"/><xsl:text>
</xsl:text>
</xsl:template>

</xsl:stylesheet>

Postnext
Edward KazanjianSubject: Extract values from XML and convert to CSV using XSLT
Author: Edward Kazanjian
Date: 25 Oct 2004 06:27 PM
I would like to create a csv file with the following columns of data

FragmentId, NPIC50DP,NPIC50EP2,NPSolubility

How do I apply this using Stylus Studio and also on the command line?

Thanks,

Edward

Postnext
Ivan PedruzziSubject: Extract values from XML and convert to CSV using XSLT
Author: Ivan Pedruzzi
Date: 25 Oct 2004 06:44 PM
Basic instructions:

- click the menu under File -> New -> XSLT: Text Editor

- When the "Scenario properties" are on the screen
click ... button near to "Source XML URL"

- When the Open Dialog is on the screen click on the button
"My Computer" then browse for your xml file, select it click
then click the open button

- click OK in the "Scenario properties" dialog

- Replace the text with the solution I posted

To learn more about Stylus Studio take a look to the video tutorials
http://www.stylusstudio.com/xml_videos.html

To invoke the command line XSLT processor read the online help chapter
"Applying a Stylesheet from the Command Line"

Ivan


Postnext
Edward KazanjianSubject: Extract values from XML and convert to CSV using XSLT
Author: Edward Kazanjian
Date: 26 Oct 2004 12:03 PM
Thank you Ivan,

I have used the xsl created by Stylus Studio in my jscript code using the xmlDom object and the transformNode method.

The resulting string is not being stored in a compatible csv file format.

When I create a scripting.filesystemobject and save the file, the csv file will not open properly.

However, when I view the xslt result in text format, it works okay.

Is there something I need to add to the xls to get the resulting csv file to open properly.

Thank you.

Edward

Postnext
Ivan PedruzziSubject: Extract values from XML and convert to CSV using XSLT
Author: Ivan Pedruzzi
Date: 26 Oct 2004 02:39 PM
Edward,

>>The resulting string is not being stored in a compatible csv file format
>>When I create a scripting.filesystemobject and save the file, the csv file will not open properly

What do you mean by that?
After the file is created on the file system can you open it notepad?
What is the content?

Keep in mind that transformOnNode seriliazes the output in Unicode format,
no metter what is the output encoding.

If you would like to generate UTF-8 you need to use XSLProcessor.transform object.
You will find plenty of examples on http://msdn.microsoft.com/xml

Ivan

Postnext
Edward KazanjianSubject: Extract values from XML and convert to CSV using XSLT
Author: Edward Kazanjian
Date: 26 Oct 2004 06:40 PM
I have searched msdn as well as many googled sites and am unable to find "working" code to create UTF-8 output.

Could you please help me out?

Thank you.

Edward

Postnext
Edward KazanjianSubject: Extract values from XML and convert to CSV using XSLT
Author: Edward Kazanjian
Date: 26 Oct 2004 01:37 PM
Is there something I need to add to the xls to get the resulting csv file to open properly?

Posttop
Ivan PedruzziSubject: Extract values from XML and convert to CSV using XSLT
Author: Ivan Pedruzzi
Date: 26 Oct 2004 07:04 PM

Immediately after the "stylesheet" element you have to define the "output" element
like this

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>



here is a full example from MSDN
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/xmconincreasingperformancebyusingthexsltemplateobject.asp

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.