[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: XML Document to ascii text file

  • From: "Robert C. Lyons" <boblyons@u...>
  • To: 'Didier PH Martin' <martind@n...>, 'Mallikarjuna Sangappa' <malliks@r...>, "'xml-dev@i...'" <xml-dev@i...>
  • Date: Wed, 9 Jun 1999 08:41:18 -0400

xd ascii
Didier wrote:
	"Can you explain how with just a simple example. ...
	 How would you transform this XML document above into a plain asci text? 
	 Can you show it with a XSL script?"

Didier,

Oops. I sent that last message too soon.

See below for an example of an XSLT stylesheet that converts an XML document
into a plain ASCII text file. The XML document is not the same as yours,
but it's fairly simple.

Here's the XML document:

<?xml version='1.0' ?>
<contacts>
    <contact>
        <full_name>Nancy Magill</full_name>
        <email_address>lil.magill@b...</email_address>
        <phone_number>(100) 555-9328</phone_number>
    </contact>
    <contact>
        <email_address>molly.jones@o...</email_address>
        <full_name>Molly Jones</full_name>
    </contact>
    <contact>
        <phone_number>(200) 555-3249</phone_number>
        <full_name>Penny Lane</full_name>
        <email_address>plane@b...</email_address>
    </contact>
</contacts>

Here's the XSLT stylesheet that converts the XML document into
an ASCII text file:

<?xml version="1.0"?>
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"
    indent-result="no" default-space="strip">

    <xsl:template match="/contacts/contact">
        <xsl:text>[contact]&#xD;&#xA;</xsl:text>
        <xsl:apply-templates select="full_name"/>
        <xsl:apply-templates select="email_address"/>
        <xsl:apply-templates select="phone_number"/>
    </xsl:template>

    <xsl:template match="full_name">
        <xsl:text>name=</xsl:text>
        <xsl:value-of select="."/>
        <xsl:text>&#xD;&#xA;</xsl:text>
    </xsl:template>

    <xsl:template match="email_address">
        <xsl:text>email=</xsl:text>
        <xsl:value-of select="."/>
        <xsl:text>&#xD;&#xA;</xsl:text>
    </xsl:template>

    <xsl:template match="phone_number">
        <xsl:text>phone=</xsl:text>
        <xsl:value-of select="."/>
        <xsl:text>&#xD;&#xA;</xsl:text>
    </xsl:template>

</xsl:stylesheet>

Here is the ASCII text file that is produced by the XSLT processor:

[contact]
name=Nancy Magill
email=lil.magill@b...
phone=(100) 555-9328
[contact]
email=molly.jones@o...
name=Molly Jones
[contact]
phone=(200) 555-3249
name=Penny Lane
email=plane@b...


Hope this helps.

Bob

------
Bob Lyons
EC Consultant
Unidex Inc.
1-732-975-9877
boblyons@u...
http://www.unidex.com/

 

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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