<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!-- ##############################################################
                            sbml_to_cellml.xsl

  ############################################################## -->
<!--=================================================-->
<!--        "SBML" to "CellML" XML stylesheet        -->
<!--                 (c) EBI 2005-2010                  -->
<!--=================================================-->
<!--

    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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA


For any inquiry regarding this file, please contact Biomodels.net support (biomodels-net-support at lists.sourceforge.net)

-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.cellml.org/cellml/1.0#" xmlns:bqs="http://www.cellml.org/bqs/1.0#" xmlns:cellml="http://www.cellml.org/cellml/1.0#" xmlns:cmeta="http://www.cellml.org/metadata/1.0#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:exsl="http://exslt.org/common" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:mathml="http://www.w3.org/1998/Math/MathML" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sbml="http://www.sbml.org/sbml/level2" xmlns:stsim="http://www.sbml.org/2001/ns/stochsim" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" extension-element-prefixes="exsl" version="1.0">

<xsl:output encoding="UTF-8" indent="yes" method="xml"/>
<xsl:include href="cellml_template.xsl"/>
<xsl:include href="cellml_variable.xsl"/>
<xsl:include href="cellml_connection.xsl"/>

<xsl:key match="sbml:listOfRules/sbml:assignmentRule|sbml:listOfRules/sbml:rateRule" name="assign_rateRule" use="@variable"/>
<xsl:key match="sbml:listOfRules/sbml:assignmentRule" name="assignmentRule" use="@variable"/>
<xsl:key match="sbml:listOfRules/sbml:rateRule" name="rateRule" use="@variable"/>
<xsl:key match="sbml:listOfReactions/sbml:reaction/sbml:listOfReactants/sbml:speciesReference" name="reactant" use="@species"/>
<xsl:key match="sbml:listOfReactions/sbml:reaction/sbml:listOfProducts/sbml:speciesReference" name="product" use="@species"/>
<xsl:key match="sbml:listOfSpecies/sbml:species" name="speciesCompartment" use="@compartment"/>
<!--xxxxxxxxxxxxxxxxkey for the listOfUnitDefinitions, use idxxxxxxxxxxxxxxx-->
<xsl:key match="sbml:listOfUnitDefinitions/sbml:unitDefinition" name="unitDef" use="@id"/>

<!--xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxnewline variablexxxxxxxxxxxxxxxxxxxxxxxxxx-->
<xsl:variable name="newline">
	<xsl:text>
	</xsl:text>
</xsl:variable>

<!--xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-->
<!--              MAIN                             -->
<!--xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-->

<xsl:template match="/">
	<xsl:variable name="modelName">
		<xsl:apply-templates select="descendant::sbml:model"/>
	</xsl:variable>

<xsl:text disable-output-escaping="yes">&lt;model name="</xsl:text>
<xsl:value-of select="$modelName"/>
<xsl:text disable-output-escaping="yes">" xmlns="http://www.cellml.org/cellml/1.0#"&gt;</xsl:text>

	<xsl:value-of select="$newline"/>
<!--write units component-->
	<xsl:comment>This is allUnits</xsl:comment>
	<xsl:value-of select="$newline"/>
	<xsl:call-template name="wUnits"/>

	<xsl:value-of select="$newline"/>
<!--write environment-->
	<xsl:comment>This is environment time</xsl:comment>
	<xsl:value-of select="$newline"/>
	<xsl:call-template name="wEnvironment"/>


	<xsl:value-of select="$newline"/>
<!--write compartment component-->
	<xsl:comment>This is compartments</xsl:comment>
	<xsl:value-of select="$newline"/>
	<xsl:for-each select="descendant::sbml:listOfCompartments/sbml:compartment">
		<xsl:call-template name="wCompartment">
			<xsl:with-param name="ID" select="@id"/>
		</xsl:call-template>
	</xsl:for-each>

	<xsl:value-of select="$newline"/>
<!--write global parameter component-->
	<xsl:comment>This is global parameter </xsl:comment>
	<xsl:value-of select="$newline"/>
	<xsl:for-each select="descendant::sbml:model/sbml:listOfParameters/sbml:parameter">
		<xsl:call-template name="wGlobalPara">
			<xsl:with-param name="ID" select="@id"/>
		</xsl:call-template>
	</xsl:for-each>

	<xsl:value-of select="$newline"/>
<!--write species-->
	<xsl:comment>This is all species</xsl:comment>
	<xsl:value-of select="$newline"/>
	<xsl:for-each select="descendant::sbml:listOfSpecies/sbml:species">
				<xsl:variable name="B">
			<xsl:choose>
			<xsl:when test="@boundaryCondition='true'">
				<xsl:value-of select="'true'"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="'false'"/>
			</xsl:otherwise>
			</xsl:choose>
			</xsl:variable>

		<xsl:call-template name="wSpecies">
			<xsl:with-param name="ID" select="@id"/>

			<xsl:with-param name="Boundary" select="$B"/>
			<xsl:with-param name="compartment" select="@compartment"/>
		</xsl:call-template>
		<xsl:value-of select="$newline"/>
	</xsl:for-each>

	<xsl:value-of select="$newline"/>
<!--write reactions-->
	<xsl:comment>This is all reactions</xsl:comment>
	<xsl:value-of select="$newline"/>
	<xsl:for-each select="descendant::sbml:listOfReactions/sbml:reaction">
		<xsl:apply-templates select="."/>
	</xsl:for-each>

	<xsl:value-of select="$newline"/>
<!--write algebraic rule-->
	<xsl:comment>This is all algebraic rule</xsl:comment>
	<xsl:value-of select="$newline"/>
	<xsl:for-each select="descendant::sbml:listOfRules/sbml:algebraicRule">
		<xsl:variable name="posi">
			<xsl:value-of select="position()"/>
		</xsl:variable>
		<xsl:call-template name="wAlgebraicRule">
			<xsl:with-param name="position" select="$posi"/>
			<xsl:with-param name="current" select="current()"/>
		</xsl:call-template>
	</xsl:for-each>

	<xsl:value-of select="$newline"/>
<!--write connection-->
	<xsl:comment>This is all connection</xsl:comment>
	<xsl:value-of select="$newline"/>
	<xsl:call-template name="wConnection"/>

	<xsl:value-of select="$newline"/>
<!--write group-->
	<xsl:comment>This is all group</xsl:comment>
	<xsl:value-of select="$newline"/>
	<xsl:call-template name="wGroup"/>

<xsl:value-of select="$newline"/>

<!--for annotation-->
	<xsl:comment>This is all annotation</xsl:comment>
	<xsl:value-of select="$newline"/>
<xsl:element name="rdf:RDF">
<xsl:for-each select="descendant::sbml:annotation/rdf:RDF">
	<xsl:apply-templates mode="general"/>
</xsl:for-each>
</xsl:element>

<xsl:value-of select="$newline"/>
<xsl:text disable-output-escaping="yes">&lt;/model&gt;</xsl:text>

</xsl:template>



</xsl:stylesheet>

