Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML to CSV with XSLT

Status
Not open for further replies.

zincyo

Programmer
Jun 13, 2007
35
US
Hey, I have 3 xml files which I need to convert to csv files. I must use XSLT to do this, and apparently accessing xalan from my command prompt is a helpful way to do this. If anyone can please give me some advice / code to point me in the right direction it would be most helpful.

Thanks!
 
Tom, thanks for your response, however that tutorial is with a semicolon separated file, and using VBA rather than XSLT.
 
zincyo said:
I must use XSLT to do this

Yes, I read that. I considered that. Hmmm....

Have a look in the deliverables for the file that has the .xsl extension. That is one of those XSLT things.

zincyo said:
using VBA rather than XSLT

A more precise analysis would lead one to the conclusion that the example uses VBScript to apply a transform rather from applying a transform from command prompt.

So, is your question, "How do I start xalan from a command prompt?"

zincyo said:
is with a semicolon separated file

It is left as an exercise to the original poster to see if he can determine where those pesky semicolons come from and change them to commas. I think it will be obvious.

Tom Morrison
 
Those tutorials are for much more basic XML, I have to do my conversion using a much more sophisticated code. This is a sample of my code, and perhaps someone can show me in this example how it would be converted using XSLT. THANKS!

- <MktDataFull src="Information" AsOfDt="2007-06-28T20:51:50Z">
- <Instrmt id="20045476" src="Information2" mSym="NWS/USCDS140F2008-2" finTyp="33" trdFactor="1">
<Control prcMethod="CFF_MODEL" ts="2007-06-28T05:00:00Z" statusMsg="" status="1" />
<Valuation Px="-13.0442" AccrdAmt="-0.35" ValueAsSpread="0.000434905" UnwindSpread="0.000419011" />
</Instrmt>
 
>I have to do my conversion using a much more sophisticated code.
But there is no such thing as a universal mapping between xml document source and csv file. One has to come up with a spec to make sense out of a mapping.
 
essentially, I need to know how to access the SRC property in line 1, without src being tagged i.e: <src>
 
zincyo said:
I need to know how to access the SRC property in line 1
The proper term for the thing in line one indicated by 'src=' is an attribute, not a property. Knowing the correct terminology is helpful to finding answers to your questions.

The 'language' used to reference pieces of XML documents is called XPath. It might be helpful to take a small online tutorial found here. In this case pay particular attention to the attribute axis which can be abbreviated using the ampersand character.


Tom Morrison
 
If that help you see!

[tt]<xsl:template match="MktDataFull" mode="getsrc">
<xsl:value-of select="@src" />
</xsl:template>[/tt]

But without a spec, the whole question is meaningless.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top