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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outputting a .txt file using an xslt stylesheet

Status
Not open for further replies.

mcbigj

Programmer
Dec 14, 2001
83
US
Is it possible to output an xml page into a .txt file?

Example
<product>
<name>bubblegum</name>
</product>

and have it ouput to a .txt file

product: bubblegum.

I can do some basic msxmlDom stuff and some basic xslt stylesheet but only see how to output a stylesheet as html or xml. Thanks for the help.
 
Of course it's possible! With a stylesheet you can infact create any possible text-based output. You say that you can output html, but the stylesheet doesn't actually know if it's html, the renderer (IE, NS, etc) does.

So if you put words in the places where you would normally put html tags, the stylesheet will have those words as output. All you have to do is to save these words to a file with the extention .txt, since a stylesheet can't do that for you.

Jordi Reineman
 
So do you recommened using the objxml.save(file) to save the file as a text file. I guess what I really want to know is if I can use xslt to create the document that I want off of an xml file and then have that output to the txt file. do I mix the xslt and xmldom?
Thanks again
 
you can output txt from xslt no problem.

<xsl:eek:utput method=&quot;text&quot; encoding=&quot;UTF8&quot;/>

this goes at the top level - ie. after your opening <xsl:stylesheet> tag. the encoding should be looked at carefully if you are using funny chars, otherwise it can be omitted.

if you also need your text to be word wrapped at 80 chars, let me know and i'll post the code for that too.
 
Thanks for the help, I won't worry about the wordwrap for now, but I do want to know this. Using xslt, can I name the output text file? From what I know, xslt takes an existing xml file and uses the xslt to transform the same existing xml file.
Thanks again MrTom.
 
the xslt 1.0 standard will only output to one file.
if your processor supports &quot;exslt&quot; then you can output to multiple files but this isn't an official extension to xsl. exslt comes from the best minds of xsl so it's not rubbish either. the wordwrap stuff can be found at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top