|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: XML->ascii Conversion
> 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








