Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cellml1to2.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,19 @@
<xsl:template match="cellml10:model | cellml11:model">
<model xmlns="http://www.cellml.org/cellml/2.0#" xmlns:cellml="http://www.cellml.org/cellml/2.0#">
<xsl:copy-of select="@name"/>
<!-- Units elements can only be declared as a child of the model element -->
<xsl:for-each select="cellml10:component/cellml10:units | cellml11:component/cellml11:units" >
<xsl:element name="{local-name()}" namespace="http://www.cellml.org/cellml/2.0#">
<xsl:apply-templates select="@* | node()"/>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will result in attributes on the units elements being ignored, since the template for @* above does nothing. Have you checked this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're correct, now I have added a copy command to copy the name attribute. Testing with the van der pol model seems to give the correct result now.

</xsl:element>
</xsl:for-each>
<xsl:apply-templates select="@* | node()"/>
</model>
</xsl:template>

<!-- Don't do anything with units that are children of components -->
<xsl:template match="cellml10:component/cellml10:units | cellml11:component/cellml11:units"/>

<!-- Variable elements need special handling for their interface attributes -->
<xsl:template match="cellml10:variable | cellml11:variable">
<xsl:element name="variable" namespace="http://www.cellml.org/cellml/2.0#">
Expand Down
16 changes: 16 additions & 0 deletions test-models/basic_model.cellml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<model xmlns="http://www.cellml.org/cellml/1.1#" xmlns:cellml="http://www.cellml.org/cellml/1.1#" xmlns:xlink="http://www.w3.org/1999/xlink" name="basic_model" id="metaid0">
<component name="environment">
<variable id="environment.t" initial_value="0" name="t" units="second"/>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply>
<eq/>
<ci>t</ci>
<apply>
<plus/>
<cn xmlns:cellml="http://www.cellml.org/cellml/1.1#" cellml:units="dimensionless">1</cn>
<cn xmlns:cellml="http://www.cellml.org/cellml/1.1#" cellml:units="dimensionless">3</cn>
</apply>
</apply>
</math>
</component>
</model>
61 changes: 61 additions & 0 deletions test-models/van_der_pol_model.cellml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version='1.0'?>
<model name="van_der_pol_model_1928" xmlns="http://www.cellml.org/cellml/1.0#" xmlns:cellml="http://www.cellml.org/cellml/1.0#">
<component name="main">
<units name="per_second">
<unit exponent="-1" units="second"/>
</units>
<variable name="time" units="second"/>
<variable initial_value="-2" name="x" units="dimensionless"/>
<variable initial_value="0" name="y" units="dimensionless"/>
<variable initial_value="1" name="epsilon" units="dimensionless"/>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply>
<eq/>
<apply>
<diff/>
<bvar>
<ci>time</ci>
</bvar>
<ci>x</ci>
</apply>
<apply>
<times/>
<ci>y</ci>
<cn cellml:units="per_second">1</cn>
</apply>
</apply>
<apply>
<eq/>
<apply>
<diff/>
<bvar>
<ci>time</ci>
</bvar>
<ci>y</ci>
</apply>
<apply>
<times/>
<apply>
<minus/>
<apply>
<times/>
<ci>epsilon</ci>
<apply>
<minus/>
<cn cellml:units="dimensionless">1</cn>
<apply>
<power/>
<ci>x</ci>
<cn cellml:units="dimensionless">2</cn>
</apply>
</apply>
<ci>y</ci>
</apply>
<ci>x</ci>
</apply>
<cn cellml:units="per_second">1</cn>
</apply>
</apply>
</math>
</component>
</model>