- Author:
- Randy Thomas <srandall.thomas@gmail.com>
- Date:
- 2014-03-05 09:04:13+01:00
- Desc:
- XSLT to convert from DAEML to Berkeley Madonna
- Permanent Source URI:
- https://models.physiomeproject.org/workspace/194/rawfile/afab9c934e31418b51ae0bdb506ca6890e3d597b/daeml2bmadonna2.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1"
xmlns:cmeta="http://www.cellml.org/metadata/1.0#"
xmlns:math="http://www.w3.org/1998/Math/MathML"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<!-- This xsl file converts (partially for now) a DAEML xml file into a Berkeley Madonna model file. -->
<!-- 24April2008: used Alfredo's cellml2hppv2.xsl -->
<xsl:output method="text" encoding="UTF-8" indent="no"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:text>METHOD stiff </xsl:text>
<xsl:text>STARTTIME = 0 </xsl:text>
<xsl:text>STOPTIME = 100 </xsl:text>
<xsl:text>DT = 0.002 </xsl:text>
<xsl:text> </xsl:text>
<xsl:text>{ </xsl:text>
<xsl:text> * </xsl:text>
<xsl:text> * Test of DAEML translation to Berkeley Madonna </xsl:text>
<xsl:text> * </xsl:text>
<xsl:text>} </xsl:text>
<xsl:text> </xsl:text>
<xsl:text>{ *** Model description*** </xsl:text>
<xsl:value-of select="daeml/model/description"/>
<xsl:text> } </xsl:text>
<!--
<xsl:call-template name="units"/>
<xsl:call-template name="parameters"/>
<xsl:call-template name="variables"/>
<xsl:call-template name="odes"/>
-->
<xsl:apply-templates select="daeml/model/list_of_units"/>
<xsl:apply-templates select="daeml/model/parameters"/>
<xsl:apply-templates select="daeml/model/variables"/>
<xsl:apply-templates select="daeml/model/system_equations/derivative_equations"/>
</xsl:template> <!-- End of main template -->
<!--
Now list the various templates.
-->
<xsl:template match="list_of_units" name="units">
<xsl:text> ; ***Units list goes here*** </xsl:text>
</xsl:template>
<xsl:template match="parameters" name="parameters">
<xsl:text> { Parameter list (values don't change during the simulation): </xsl:text>
<xsl:for-each select="parameter">
<xsl:text>	 </xsl:text><!-- tabulation -->
<xsl:value-of select="@name"/>
<xsl:text> (</xsl:text>
<xsl:value-of select="@units"/>
<xsl:text>), types: </xsl:text>
<xsl:for-each select="type">
<xsl:value-of select="."/>
</xsl:for-each>
<xsl:text>; </xsl:text>
<xsl:value-of select="comment"/>
<xsl:text> </xsl:text>
</xsl:for-each>
<xsl:text>} </xsl:text>
<xsl:text> ; ***Parameter values: </xsl:text>
<xsl:for-each select="parameter">
<xsl:choose>
<xsl:when test="init_value/eq_code/text()">
<xsl:value-of select="init_value/eq_code"/>
<xsl:text> </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="definition/eq_code"/>
<xsl:text> </xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<xsl:template match="variables" name="variables">
<!-- First, list the variables in a comment. -->
<xsl:text> { Variables (values may change during the simulation): </xsl:text>
<xsl:for-each select="variable">
<xsl:text>	 </xsl:text><!-- tabulation -->
<xsl:value-of select="@name"/>
<xsl:text> (</xsl:text>
<xsl:value-of select="@units"/>
<xsl:text>), types: </xsl:text>
<xsl:if test="@state_var='true'">
<xsl:text>state </xsl:text>
</xsl:if>
<xsl:for-each select="type">
<xsl:value-of select="."/>
<xsl:text> </xsl:text>
</xsl:for-each>
<xsl:text>; </xsl:text>
<xsl:value-of select="comment"/>
<xsl:text> </xsl:text>
</xsl:for-each>
<xsl:text>} </xsl:text>
<!-- Next, give the variable values and definitions. -->
<xsl:text> ; ***Variable values and definitions: </xsl:text>
<xsl:for-each select="variable">
<xsl:choose>
<xsl:when test="not(@state_var='true')">
<xsl:choose>
<xsl:when test="init_value/eq_code/text()">
<xsl:value-of select="init_value/eq_code"/>
<xsl:text> </xsl:text>
</xsl:when>
<xsl:when test="definition/eq_code/text()">
<xsl:value-of select="definition/eq_code"/>
<xsl:text> </xsl:text>
</xsl:when>
<xsl:when test="definition/function_call">
<xsl:apply-templates match="definition/function_call">
<xsl:with-param name="func_name" select="definition/function_call/@name"/>
<xsl:with-param name="caller_index" select="position()"/>
</xsl:apply-templates>
</xsl:when>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:for-each>
<xsl:text> </xsl:text>
<!-- Next, initialize the state variables. -->
<xsl:text>; *** initialize state variables *** </xsl:text>
<xsl:for-each select="variable">
<xsl:if test="@state_var='true'">
<xsl:text>INIT </xsl:text>
<xsl:value-of select="init_value/eq_code"/>
<xsl:text> </xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text> </xsl:text>
<!-- Finally, set limits, if any, for the state variables. -->
<xsl:text>; *** range conditions for the state variables *** </xsl:text>
<xsl:for-each select="variable">
<xsl:if test="@state_var='true'">
<xsl:for-each select="condition">
<xsl:text>LIMIT </xsl:text>
<xsl:value-of select="eq_code"/>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="derivative_equations" name="odes">
<xsl:text>; *** ODEs *** </xsl:text>
<xsl:for-each select="ode">
<xsl:value-of select="eq_code"/>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:template>
<!-- NB: put function definitions off for later:
<xsl:template match="definition/function_call">
<xsl:param name="func_name"/>
<xsl:param name="caller_index"/>
<xsl:for-each select="map">
<xsl:variable name="
<if test="/daeml/function/@functionName=$func_name">
<if test="daeml/function/variable/@name=
</xsl:template>
-->
</xsl:stylesheet>