/*
 *  SPL - The SPL Programming Language
 *  Copyright (C) 2004, 2005  Clifford Wolf <clifford@clifford.at>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  example53.spl: simple XSLT example
 */

// SKIP_IF_NO_LIBXML2
// SKIP_IF_NO_LIBXSLT
load "xml";

var xmldoc = xml_parse(<:>
	: <?xml version="1.0"?>
	: <swlist>
	:	<software name="ROCK Linux">
	:		<author>Clifford Wolf</author>
	:		<desc>Distribution Built Kit</desc>
	:	</software>
	:	<software name="dietlibc">
	:		<author>Felix von Leitner</author>
	:		<desc>A small C library</desc>
	:	</software>
	:	<software name="gatling">
	:		<author>Felix von Leitner</author>
	:		<desc>A high performance web server</desc>
	:	</software>
	:	<software name="Ambassador of Pain">
	:		<author>Raffi and Clifford</author>
	:		<desc>A game for the text console</desc>
	:	</software>
	:	<software name="SPL">
	:		<author>Clifford Wolf</author>
	:		<desc>Yet another Scripting Language</desc>
	:	</software>
	: </swlist>
</>);

var xsldoc = xml_parse(<:>
	: <?xml version="1.0"?>
	: <xsl:stylesheet version="1.0"
	:	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	:	xmlns:set="http://exslt.org/sets"
	:	extension-element-prefixes="set">
	: <xsl:output method="xml" indent="yes"/>
	: <xsl:param name="ignore"/>
	: <xsl:template match="/">
	: <swlist-by-author>
	:	<xsl:for-each select="swlist/software[
	:			not(author = preceding-sibling::software/author) and
	:			not(string-length($$ignore) > 0 and contains(author, $$ignore))]">
	:		<author name="{author}">
	:			<xsl:variable name="a" select="author"/>
	:			<xsl:for-each select="../software[string(author)=$$a]">
	:				<software>
	:					<name><xsl:value-of select="@name"/></name>
	:					<desc><xsl:value-of select="desc"/></desc>
	:				</software>
	:			</xsl:for-each>
	:		</author>
	:	</xsl:for-each>
	:	<exslt-demo>
	:		<xsl:for-each select="set:distinct(//author)">
	:			<author><xsl:value-of select="." /></author>
	:		</xsl:for-each>
	:	</exslt-demo>
	: </swlist-by-author>
	: </xsl:template>
	: </xsl:stylesheet>
</>);

debug xml_xslt_text(xmldoc, xsldoc, ignore: "'Raffi'");

