XML Document to ascii text file
Robert C. Lyons
boblyons at unidex.com
Wed Jun 9 14:37:10 BST 1999
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 at blackmountainhills.com</email_address>
<phone_number>(100) 555-9328</phone_number>
</contact>
<contact>
<email_address>molly.jones at oblada.com</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 at bluesuburbanskies.com</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]
</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>
</xsl:text>
</xsl:template>
<xsl:template match="email_address">
<xsl:text>email=</xsl:text>
<xsl:value-of select="."/>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="phone_number">
<xsl:text>phone=</xsl:text>
<xsl:value-of select="."/>
<xsl:text>
</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 at blackmountainhills.com
phone=(100) 555-9328
[contact]
email=molly.jones at oblada.com
name=Molly Jones
[contact]
phone=(200) 555-3249
name=Penny Lane
email=plane at bluesuburbanskies.com
Hope this helps.
Bob
------
Bob Lyons
EC Consultant
Unidex Inc.
1-732-975-9877
boblyons at unidex.com
http://www.unidex.com/
xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To (un)subscribe, mailto:majordomo at ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)
More information about the Xml-dev
mailing list