<?xml version="1.0" encoding="ISO-8859-1"?>
<!--

    FiReportXML - Rapid XML Report Generator
    Copyright (C) 2004  Daniel McFeeters

    included with

    FiForms - A collection of PHP classes designed
    to facilitate rapid development of web-database software

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


    The original author of this library can be contacted at the following
    address:

    Daniel McFeeters
    182 Baker Rd.
    Faubush, KY 42544-6526
    email:databases at alltel dot net


Project Started January 20, 2004
*******************************************************************************
makecsv.xsl

Translates a FiReport result into Comma-delimited text, which can be 
imported into a spreadsheet

The tree-structure is denormalized into a 2-dimensional sheet.
*******************************************************************************
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text" />
    <xsl:strip-space elements="row field"/>

    <xsl:template match="/">
	<xsl:apply-templates select="/report/dataset"/>
    </xsl:template>

    <xsl:template match="/report/dataset">
	<xsl:variable name="HEADINGROWS" select="descendant::row[not(dataset/row)]" />
	<xsl:for-each select="$HEADINGROWS[1]">
		<xsl:apply-templates select="ancestor::row/field" mode="headings"/>
		<xsl:apply-templates select="field" mode="headings" />
	    
	        <xsl:text>
</xsl:text>
	</xsl:for-each>
	<xsl:apply-templates select="descendant::row" mode="bottom"/>
	        <xsl:text>

</xsl:text>
    </xsl:template>

    <xsl:template match="row" mode="headings">
    </xsl:template>

    <xsl:template match="row[not(dataset/row)]" mode="bottom">
	<xsl:apply-templates select="ancestor::row/field" mode="ascending"/>
	<xsl:apply-templates select="field" mode="ascending" />
	<xsl:text>
</xsl:text>
    </xsl:template>

    <xsl:template match="field" mode="ascending">
	<xsl:text>&quot;</xsl:text>
	<xsl:value-of select="." />
	<xsl:text>&quot;,</xsl:text>
    </xsl:template>
    
    <xsl:template match="field" mode="headings">
	<xsl:text>&quot;</xsl:text>
	<xsl:value-of select="@name" />
	<xsl:text>&quot;,</xsl:text>
    </xsl:template>
    
    <xsl:template match="row" mode="bottom">
    </xsl:template>

    <xsl:template match="field">
    </xsl:template>

</xsl:stylesheet>  


