Results 1 to 5 of 5

Thread: xml to txt

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Posts
    103

    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)

  2. #2
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240
    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Posts
    103
    not really the answer i expected, does somebody knows how to do it with xsl?

  4. #4
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    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>

  5. #5
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    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
  •  



Click Here to Expand Forum to Full Width