Subject: RE: XML->ascii Conversion
From: Mike Brown <mbrown@xxxxxxxxxxxxx>
Date: Thu, 19 Aug 1999 17:14:19 -0600
|
> I want to translate the following...
>
> <orderlist>
> <order ordernum="1">
> <customer>
> <firstname>John</firstname>
> <lastname>Doe</lastname>
> <phone>(510) 555-1212</phone>
> </customer
> </order>
> <order ordernum="2">
> <customer>
> <firstname>Jane</firstname>
> <lastname>Smith</lastname>
> <phone>(916) 555-1212</phone>
> </customer
> </order>
> </orderlist>
>
> into a tab-delimited ascii file for import into QuickBooks like this...
>
> firstname lastname phone
> John Doe (510) 555-1212
> Jane Smith (916) 555-1212
Here you go, with some comments to explain:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">
<!-- if using an implementation of the current XSLT WD -->
<xsl:output method="text"/>
<!-- execute this template if the element name is 'orderlist' -->
<xsl:template match="orderlist">
<!-- emit column headers with tabs and a newline -->
<xsl:text>firstname	lastname	phone
</xsl:text>
<!-- process elements named 'customer' that are children of
elements named 'order' that are children of the current
node -->
<xsl:for-each select="order/customer">
<!-- select as a node-set the elements named 'firstname'
that are children of the current node, and emit the
concatenation of text nodes contained within the
first node in that node-set -->
<xsl:value-of select="firstname"/>
<xsl:text>	</xsl:text>
<xsl:value-of select="lastname"/>
<xsl:text>	</xsl:text>
<xsl:value-of select="phone"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|
Mike Brown - Thu, 19 Aug 1999 17:14:19 -0600 <=
Charlotte Allen - Thu, 19 Aug 1999 16:19:19 -0700 (PDT)
|
|