|
-
May 31st, 2002, 08:03 AM
#1
Thread Starter
Lively Member
xml to txt
how can i transform a xml file to a text file with xsl?
i.e.:
<person>
<name>christopher</name>
<address>street 12</address>
</person>
how can i put this information in a textfile?
i.e.:
christopher street 12
(name has to begin on position 1, address on position 33)
-
Jun 1st, 2002, 01:47 AM
#2
Addicted Member
Not sure what XSL is.
If all you've got is 50 addresses, I'd do it by hand. Any more than that, I'd write a program. Probably a perl script using an xml module. Since the XML there looks small, I'd use a module that stores the entire XML into a tree structure first then you can traverse the tree. Alternately if the files are big, you can use an interrupt driven module that can handle large XML files which will process the file a little at a time and write the results as you go.
I've also written some Java that read XML using SAX. What a pain! I'd go for Perl any day before Java!
cudabean
-
Jun 1st, 2002, 10:58 AM
#3
Thread Starter
Lively Member
not really the answer i expected, does somebody knows how to do it with xsl?
-
Jun 1st, 2002, 07:43 PM
#4
PowerPoster
You may want to check my syntax..I just wrote it in notepad.
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates select="/person"/>
</xsl:template>
<xsl:template match="person">
Name: <xsl:value-of select="name"/>
Address: <xsl:value-of select="address"/>
</xsl:template>
</xsl:stylesheet>
-
Jun 1st, 2002, 07:59 PM
#5
Fanatic Member
yes, it involves writing the XSL Style sheet and then using a script in html to "transformNode":
Code:
<HTML>
<HEAD.
<TITLE>XSL Example</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function showXML() {
xslOutput.innerHTML = xmlData.transformNode(xslStyle.XMLDocument)
}
</SCRIPT>
</HEAD>
<BODY onload="showXML()">
<XML ID = xmlData" SRC="your_data_source.xml"></XML>
<XML ID="xmlStyle" SRC="your_XSL_sheet.xml"></XML>
<DIV ID="xslOutput"></DIV>
</BODY>
</HTML>
Style Sheet:
Code:
<?xml version='1.0' ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"?
<xsl:template match="/">
<xsl:for-each select="people/person">
<xsl:value-of select="name"/> <xsl:value-of select="address"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
you can make that more HTMLish if you want
you can also include it inline instead of in another file.
you can include the style sheet inline if you want instead.
GWDASH
[b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|