Hi Andrew,

Older versions of javac with Unicode source code did not have a problem with
LF CR.

It is pretty difficult but I believe the rewards are high.  For example any
math world that people use such as MathCad, Mathematica, Amaya, etc. that
can produce mathml output can be used as the place to figure things out and
then with these transforms, generate a part of a Java application, applet or
servlet.  Unfortunately most of these are not compliant with w3c. I'm also
designing a solution for a x-ray diffraction metrology tool where the
calibration curves need to be figured out over time where the calibration
equations can be written in mathml and the software system pick them up and
make the Java code that is needed on the fly; no need to write and compile
the source by hand so we don't have version control issues. Also can
transform to svg for representation on a webapp for providing documentation
for the system dynamically.

Also another thing that it does rather well is perform math table functions,
the integral of 1/x over 1 to t is ln(t) for example; being able to use
abstract mathematical relationship to reduce computation, optimize for speed
for unique cases and reduce code.

I'm including some of what I've got and where I am at.  I want to make a
completely working example for Xalan, albeit have some problems needing
solutions. Obviously Xslt 2.0 will make some of this much easier.  I've
included WingSection.mml and mathml2Java.xsl (and imports).  (Note: the
mathml2.dtd is local because I'm working on a laptop often offline.) Does
not yet produce compilable and usable source code for the following reasons:

1. LF CR issue.
2. packaging needs to be addressed.
3. The name of the class needs to be the same as the Java source code file
name.
4. I haven't worked out a way to define variables uniquely.  Right now I get
as many as there are usage which can be explosively wrong.

I have a few more mathml test examples if you are interested.

I've toyed with making it a NetBeans module or start a sourceforge project,
build it to work directly from an application and also as a NetBeans module.
If you know of any like minded project already in progress, please let me
know.  I've tried to interest some of my academic friends but they are more
interested in plugging away in Fortran siting all the usual FUD:-)

r,

Roger

----- Original Message ----- 
From: "Andrew Welch" <[EMAIL PROTECTED]>
To: "Roger I Martin PhD" <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Tuesday, August 19, 2003 4:20 AM
Subject: RE: text output encoding UTF-16 and controlling LF and CR



Hi,

I don't think it's possible to control the line endings produced from a
transform.  The usual answer is that it doesn't matter what line endings are
produced, as when they are read in by any conformant xml parser they will be
normalized to &_#xa; (underscore for converting mailers).

So I guess the answer is to look at what is reading the xml back in.  You
say in your post that you are generating java source code from the
transform - that sounds pretty cool (and pretty difficult!) can you post a
sample?

cheers
andrew

===
Hi,

I'm generating Java source code from mathml using xslt. I also output in
Unicode format for including Greek symbols (often in the original mathml and
translates nicely). But I have the problem that the LF CR output does not
get accepted by the jdk1.4 compiler(javac). I believe javac expects Unicode
with only LF. Does anyone know how to crontrol LF CR output?

--Roger
===

Attachment: WingSection.mml
Description: Binary data

<?xml version="1.0"?>
<xsl:stylesheet  version="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";>
<!--xsl:stylesheet  version="1.0" 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"; xmlns:math="http://www.w3.org/TR/MathML2"-->
<xsl:import href="linearAlgebra.xsl"/>
<xsl:import href="statistics.xsl"/>
  <xsl:output method="text" encoding="UTF-16" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="math:math" name="math">
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match="math:apply" name="apply">
    <xsl:apply-templates select="./*[position()=1]"/>
    <xsl:if test="parent::*[name()='math']">;
    </xsl:if>
</xsl:template>

<xsl:template match="/">
  <xsl:text>
public class Equation extends Object
{
    public Equation()
    {
    }
    
    public void crunch()
    {
</xsl:text>
    <xsl:apply-templates />
  <xsl:text>
    }
    
    </xsl:text>
    <xsl:call-template name='variables'/>
    <xsl:text>
    
    private double determinant(javax.vecmath.GMatrix A)
    {
        double det=0.0;
        double sign=1.0;
        for(int j=0;j&lt;A.getNumCol();j++)
        {
            int permutator=j;
            double value=0.0;
            for(int i=0;i&lt;A.getNumRow();i++)
            {
                value*=A.getElement(i, permutator++);
                if(permutator>=A.getNumCol())permutator=0;
            }
            det+=(sign*value);
            sign*=-1.0;
        }
    }
    
    private double magnitude(javax.vecmath.GVector V)
    {
        double magnitudeSquared=0.0;
        for(int i=0;i&lt;V.getSize();i++)
        {
        magnitudeSquared+=Math.pow(V.getElement(i), 2);
        }
        return Math.sqrt(magnitudeSquared);
    }
    
    private double mean(double[] array)
    {
        double sum=0.0;
        for(int i=0;i&lt;array.length;i++)
        {
        sum+=array[i];
        }
        return sum/array.length;
    }
    
    private double mean(long[] array)
    {
        double sum=0.0;
        for(int i=0;i&lt;array.length;i++)
        {
        sum+=array[i];
        }
        return sum/array.length;
    }
    
    private double mean(int[] array)
    {
        double sum=0.0;
        for(int i=0;i&lt;array.length;i++)
        {
        sum+=array[i];
        }
        return sum/array.length;
    }
    
    private double variance(double[] array)
    {
        double sum=0.0;
        double meanValue=mean(array);
        for(int i=0;i&lt;array.length;i++)
        {
        sum+=Math.pow(array[i]-meanValue, 2.0);
        }
        return sum/(array.length-1);
    }
    
    private double variance(long[] array)
    {
        double sum=0.0;
        double meanValue=mean(array);
        for(int i=0;i&lt;array.length;i++)
        {
        sum+=Math.pow(array[i]-meanValue, 2.0);
        }
        return sum/(array.length-1);
    }
    
    private double variance(int[] array)
    {
        double sum=0.0;
        double meanValue=mean(array);
        for(int i=0;i&lt;array.length;i++)
        {
        sum+=Math.pow(array[i]-meanValue, 2.0);
        }
        return sum/(array.length-1);
    }
    
    private double standardDeviation(double[] array)
    {
        return Math.sqrt(variance(array));
    }
    
    private double standardDeviation(long[] array)
    {
        return Math.sqrt(variance(array));
    }
    
    private double standardDeviation(int[] array)
    {
        return Math.sqrt(variance(array));
    }
    
    //Have this somewhere
    private double median(double[] array)
    {
        return 0.0;
    }
    
    private double median(long[] array)
    {
        return 0.0;
    }
    
    private double median(int[] array)
    {
        return 0.0;
    }
    
    //fill in
    private double mode(double[] array)
    {
        return 0.0;
    }
    
    private double mode(long[] array)
    {
        return 0.0;
    }
    
    private double mode(int[] array)
    {
        return 0.0;
    }
    
    //Think I know but need to check
    private double moment(double[] array, int p, int degree)
    {
        return 0.0;
    }
    
    private double moment(long[] array, int p, int degree)
    {
        return 0.0;
    }
    private double moment(int[] array, int p, int degree)
    {
        return 0.0;
    }
    
    private javax.vecmath.Matrix3d genericMatrix3d=null;
    private javax.vecmath.Matrix4d genericMatrix4d=null;
}
</xsl:text>
</xsl:template>

<xsl:template name="variables">
    <xsl:for-each select="node()">
    <xsl:if test="local-name()='ci'">
    protected double <xsl:value-of select="."/>=0.0;
    </xsl:if>
    <xsl:if test="not(local-name()='ci')">
    <xsl:call-template name='variables'/>
    </xsl:if>
    </xsl:for-each>
</xsl:template>

<xsl:template match="math:mrow">
  <!--xsl:for-each select="./*"-->
   <!--xsl:value-of select="name()"/-->
    <xsl:apply-templates select="./*"/>
  <!--/xsl:for-each-->
  <xsl:if test="parent::*[name()='math']">
    <xsl:text>;
    </xsl:text>
  </xsl:if>
</xsl:template>

<xsl:template match="math:semantics">
    <xsl:apply-templates select="./*"/>
  <xsl:if test="parent::*[name()='math']">
    <xsl:text>;
    </xsl:text>
  </xsl:if>
</xsl:template>

<xsl:template match="math:annotation-xml">
</xsl:template>

<xsl:template match="math:plus" name="plus">
  <xsl:text>(</xsl:text>
  <xsl:for-each select="parent::math:apply/*[position()>1]">
    <xsl:if test="not(position()=1)">
      <xsl:text>+</xsl:text>
    </xsl:if>
    <xsl:apply-templates select="."/>
  </xsl:for-each>
  <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:minus" name="minus">
  <xsl:text>(</xsl:text>
  <xsl:for-each select="parent::math:apply/*[position()>1]">
    <xsl:if test="not(position()=1)">
      <xsl:text>-</xsl:text>
    </xsl:if>
    <xsl:apply-templates select="."/>
  </xsl:for-each>
  <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:times" name="times">
  <xsl:text>(</xsl:text>
  <xsl:for-each select="parent::math:apply/*[position()>1]">
  <xsl:if test="not(position()=1)">
    <xsl:text>*</xsl:text>
  </xsl:if>
    <xsl:apply-templates select="."/>
  <!--xsl:if test="not(local-name()='apply')">
    <xsl:apply-templates select="."/>
   </xsl:if>
  <xsl:if test="local-name()='apply'">
    <xsl:apply-templates select="."/>
  </xsl:if-->
  </xsl:for-each>
      <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:divide" name="divide">
  <!--xsl:text>(</xsl:text>
  <xsl:for-each select="./*">
  <xsl:if test="not(position()=1)">
    <xsl:text>/</xsl:text>
  </xsl:if>
  <xsl:if test="not(local-name()='apply')">
    <xsl:value-of select="."/>
   </xsl:if>
  <xsl:if test="local-name()='apply'">
    <xsl:apply-templates/>
  </xsl:if>
  </xsl:for-each>
      <xsl:text>)</xsl:text-->
    <xsl:apply-templates select="ancestor::apply/*[2]"/>
     <xsl:text>/</xsl:text>
    <xsl:apply-templates select="ancestor::apply/*[3]"/>
</xsl:template>

<xsl:template match="math:msup|math:power">
  <xsl:text>Math.pow(</xsl:text>
  <xsl:for-each select="./*">
    <xsl:value-of select="." disable-output-escaping = "yes"/>
    <xsl:if test="not(position()>1)">
      <xsl:text>, </xsl:text>
    </xsl:if>
  </xsl:for-each>
  <xsl:text>)</xsl:text>
</xsl:template>

<!--xsl:template match="msubsup/mo[position()=1 and text()='&#x0222B;'] /msubsup/mn[position()=1] /msubsup/mi[position()=1]"-->
<xsl:template match="math:msubsup[position()=1] /child::math:mo[position()=1 and text()='&#x0222B;']">
  <xsl:variable name="lower-limit" select="../child::math:*[2]"/>
  <xsl:variable name="upper-limit" select="../child::math:*[3]"/>
  <xsl:variable name="differential" select="../following-sibling::math:* //*[text()='&#x02146;'] /following-sibling::math:*"/>
  <!--xsl:text>//We're here.
  </xsl:text-->
    <!--xsl:value-of select="$lower-limit" disable-output-escaping = "yes"/>
    <xsl:value-of select="$upper-limit" disable-output-escaping = "yes"/>
    <xsl:value-of select="$differential" disable-output-escaping = "yes"/-->
    <xsl:if test="../following-sibling::math:mfrac /child::math:mrow /following-sibling::math:mi[text()=$differential]">
      <xsl:text>Math.log(</xsl:text>
      <xsl:value-of select="$upper-limit" disable-output-escaping = "yes"/>
      <xsl:text>)-Math.log(</xsl:text>
      <xsl:value-of select="$lower-limit" disable-output-escaping = "yes"/>
      <xsl:text>);
      </xsl:text>
    </xsl:if>
  <!--xsl:call-template name="log-integral"/-->
  <!--xsl:for-each select="../following-sibling::mfrac /child::mrow /following-sibling::mi[text()=$differential]">
      <xsl:value-of select="name()" disable-output-escaping = "yes"/>
      <xsl:text>, </xsl:text>
      <xsl:text> and here
      </xsl:text>
  </xsl:for-each-->
</xsl:template>

<xsl:template match="math:mfrac" name="log-integral">
      <xsl:text> log-integral
      </xsl:text>
  <xsl:for-each select="./*">
    <!--xsl:if test="position()=1"-->
      <xsl:value-of select="name()" disable-output-escaping = "yes"/>
      <xsl:text>, </xsl:text>
    <!--/xsl:if-->
      <xsl:text> and here
      </xsl:text>
  </xsl:for-each>
</xsl:template>

<xsl:template match="math:msqrt|math:mroot">
  <xsl:text>Math.sqrt(</xsl:text>
  <xsl:for-each select="./*">
    <xsl:value-of select="." disable-output-escaping = "yes"/>
    <xsl:if test="not(position()>1)">
      <xsl:text>, </xsl:text>
    </xsl:if>
  </xsl:for-each>
  <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:mfrac">
  <xsl:text>(</xsl:text>
  <xsl:for-each select="./child::*">
    <xsl:value-of select="." disable-output-escaping = "yes"/>
    <xsl:if test="not(position()>1)">
      <xsl:text>/</xsl:text>
    </xsl:if>
  </xsl:for-each>
  <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:mo">
  <xsl:choose>
   <xsl:when test="text()='&#x02062;'">
     <xsl:text>*</xsl:text>
   </xsl:when>
   <xsl:when test="text()='+'">
     <xsl:text>+</xsl:text>
   </xsl:when>
   <xsl:otherwise>
     <xsl:value-of select="text()" disable-output-escaping = "yes"/>
      <!--xsl:apply-templates select="@*"/-->
   </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="math:eq" name="eq">
    <!--xsl:apply-templates select="parent::math:apply/*[2]"/>
     <xsl:text>=</xsl:text>
    <xsl:apply-templates select="parent::math:apply/*[3]"/-->
  <xsl:for-each select="parent::math:apply/*[position()>1]">
  <xsl:if test="not(position()=1)">
    <xsl:text>=</xsl:text>
  </xsl:if>
    <xsl:apply-templates select="."/>
  </xsl:for-each>
</xsl:template>

<xsl:template match="math:ci" name="ci">
     <xsl:value-of select="."/>
</xsl:template>

<xsl:template match="math:cn" name="cn">
     <xsl:value-of select="."/>
</xsl:template>

<xsl:template match="math:pi">
     <xsl:text>Math.PI</xsl:text>
</xsl:template>

<xsl:template match="math:exp">
  <xsl:variable name="variable" select="parent::math:apply/*[2]"/>
     <xsl:text>Math.exp(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:ln">
  <xsl:variable name="variable" select="parent::math:apply/*[2]"/>
     <xsl:text>Math.log(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:log">
  <xsl:variable name="variable" select="parent::math:apply/*[3]"/>
  <xsl:variable name="base" select="parent::apply/*[2]"/>
     <xsl:text>Math.log(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)/Math.log(</xsl:text><xsl:value-of select="$base"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:sin">
  <xsl:variable name="variable" select="parent::math:apply/*[2]"/>
     <xsl:text>Math.sin(</xsl:text><xsl:apply-templates select="parent::math:apply/*[2]"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:cos">
  <xsl:variable name="variable" select="parent::math:apply/*[2]"/>
     <xsl:text>Math.cos(</xsl:text><xsl:apply-templates select="parent::math:apply/*[2]"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:tan">
  <xsl:variable name="variable" select="parent::apply/*[2]"/>
     <xsl:text>Math.tan(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:sec">
  <xsl:variable name="variable" select="parent::apply/*[2]"/>
     <xsl:text>Math.sec(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:csc">
  <xsl:variable name="variable" select="parent::apply/*[2]"/>
     <xsl:text>Math.csc(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:cot">
  <xsl:variable name="variable" select="parent::apply/*[2]"/>
     <xsl:text>Math.cot(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:sinh">
  <xsl:variable name="variable" select="parent::apply/*[2]"/>
     <xsl:text>Math.sinh(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:cosh">
  <xsl:variable name="variable" select="parent::apply/*[2]"/>
     <xsl:text>Math.cosh(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:tanh">
  <xsl:variable name="variable" select="parent::apply/*[2]"/>
     <xsl:text>Math.tanh(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:sech">
  <xsl:variable name="variable" select="parent::apply/*[2]"/>
     <xsl:text>Math.sech(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:csch">
  <xsl:variable name="variable" select="parent::apply/*[2]"/>
     <xsl:text>Math.csch(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:coth">
  <xsl:variable name="variable" select="parent::apply/*[2]"/>
     <xsl:text>Math.coth(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:arcsin">
  <xsl:variable name="variable" select="parent::apply/*[2]"/>
     <xsl:text>Math.asin(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:arccos">
  <xsl:variable name="variable" select="parent::apply/*[2]"/>
     <xsl:text>Math.acos(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:atan">
  <xsl:variable name="variable" select="parent::apply/*[2]"/>
     <xsl:text>Math.atan(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:arccosh">
  <xsl:variable name="variable" select="parent::apply/*[2]"/>
     <xsl:text>Math.arccosh(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:arccot">
  <xsl:variable name="variable" select="parent::apply/*[2]"/>
     <xsl:text>Math.arccot(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:arccoth">
  <xsl:variable name="variable" select="parent::apply/*[2]"/>
     <xsl:text>Math.arccoth(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:arccsc">
  <xsl:variable name="variable" select="parent::apply/*[2]"/>
     <xsl:text>Math.arccsc(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:arccsch">
  <xsl:variable name="variable" select="parent::apply/*[2]"/>
     <xsl:text>Math.arccsch(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:arcsec">
  <xsl:variable name="variable" select="parent::apply/*[2]"/>
     <xsl:text>Math.arcsec(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:arcsech">
  <xsl:variable name="variable" select="parent::apply/*[2]"/>
     <xsl:text>Math.arcsech(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:arcsinh">
  <xsl:variable name="variable" select="parent::apply/*[2]"/>
     <xsl:text>Math.arcsinh(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:arctanh">
  <xsl:variable name="variable" select="parent::apply/*[2]"/>
     <xsl:text>Math.arctanh(</xsl:text><xsl:value-of select="$variable"/>
     <xsl:text>)</xsl:text>
</xsl:template>

</xsl:stylesheet>
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; xmlns:fo="http://www.w3.org/1999/XSL/Format"; xmlns:math="http://www.w3.org/1998/Math/MathML"; version="1.0">
  <xsl:output method="text" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="math:vector">
     <xsl:text>new javax.vecmath.GVector(double[]{</xsl:text>
  <xsl:for-each select="./*">
    <xsl:value-of select="." disable-output-escaping = "yes"/>
    <xsl:if test="position()&lt;last()">
      <xsl:text>, </xsl:text>
    </xsl:if>
  </xsl:for-each>
     <xsl:text>})</xsl:text>
</xsl:template>

<xsl:template match="math:matrix">
     <xsl:text>new javax.vecmath.GMatrix(</xsl:text>
     <xsl:value-of select="count(./*)"/>
     <xsl:text>, </xsl:text>
     <xsl:value-of select="count(./*[1]/*)"/>
     <xsl:text>, double[]{</xsl:text>
  <xsl:for-each select="./*">
    <xsl:call-template name="matrixrow"/>
    <xsl:if test="position()&lt;last()">
      <xsl:text>, </xsl:text>
    </xsl:if>
  </xsl:for-each>
     <xsl:text>})</xsl:text>
</xsl:template>

<xsl:template match="math:matrixrow" name="matrixrow">
  <xsl:for-each select="./*">
    <xsl:value-of select="." disable-output-escaping = "yes"/>
    <xsl:if test="position()&lt;last()">
      <xsl:text>, </xsl:text>
    </xsl:if>
  </xsl:for-each>
</xsl:template>

<!-- not perfect yet need to learn keys? and id? so the xsl can discover the
current dimensions of the matrix.  There is also the problem of the matrix 
being defined later.-->
<xsl:template match="math:determinant">
  <xsl:variable name="matrix" select="parent::math:apply/*[2]"/>
    <xsl:text>double det=0.0;
    if(</xsl:text><xsl:value-of select="$matrix"/><xsl:text>.getNumCol()==2)
    {
        det=</xsl:text><xsl:value-of select="$matrix"/><xsl:text>.getElement(1,1)*</xsl:text><xsl:value-of select="$matrix"/><xsl:text>.getElement(2,2)-</xsl:text><xsl:value-of select="$matrix"/><xsl:text>.getElement(1,2)*</xsl:text><xsl:value-of select="$matrix"/><xsl:text>.getElement(2,1);
    }
    else if(</xsl:text><xsl:value-of select="$matrix"/><xsl:text>.getNumCol()==3)
    {
        genericMatrix3d=new javax.vecmath.Matrix3d();
        </xsl:text><xsl:value-of select="$matrix"/><xsl:text>.get(genericMatrix3d);
        det=genericMatrix3d.determinant();
    }
    else if(</xsl:text><xsl:value-of select="$matrix"/><xsl:text>.getNumCol()==4)
    {
        genericMatrix4d=new javax.vecmath.Matrix4d();
        </xsl:text><xsl:value-of select="$matrix"/><xsl:text>.get(genericMatrix4d);
        det=genericMatrix4d.determinant();
    }
    else
    {
        det=determinant(</xsl:text><xsl:value-of select="$matrix"/><xsl:text>)
    }
    </xsl:text>
</xsl:template>

<xsl:template match="math:transpose">
  <xsl:variable name="matrix" select="parent::math:apply/*[2]"/>
  <xsl:text></xsl:text><xsl:value-of select="$matrix"/><xsl:text>.transpose()</xsl:text>
</xsl:template>

<xsl:template match="math:selector">
  <xsl:variable name="matrix" select="parent::math:apply/*[2]"/>
  <xsl:variable name="i" select="parent::math:apply/*[3]"/>
  <xsl:variable name="j" select="parent::math:apply/*[4]"/>
  <xsl:text></xsl:text><xsl:value-of select="$matrix"/><xsl:text>.getElement(</xsl:text><xsl:value-of select="$i"/><xsl:text>, </xsl:text><xsl:value-of select="$j"/><xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:scalarproduct">
  <xsl:variable name="vector1" select="parent::math:apply/*[2]"/>
  <xsl:variable name="vector2" select="parent::math:apply/*[3]"/>
  <xsl:text></xsl:text><xsl:value-of select="$vector1"/><xsl:text>.dot(</xsl:text><xsl:value-of select="$vector2"/><xsl:text>)</xsl:text>
</xsl:template>

<!-- not sure what an outerproduct is-->
<xsl:template match="math:outerproduct">
  <xsl:variable name="vector1" select="parent::math:apply/*[2]"/>
  <xsl:variable name="vector2" select="parent::math:apply/*[3]"/>
  <xsl:text></xsl:text><xsl:value-of select="$vector1"/><xsl:text>.dot(</xsl:text><xsl:value-of select="$vector2"/><xsl:text>)</xsl:text>
</xsl:template>

<!-- not completed yet-->
<xsl:template match="math:vectorproduct">
  <xsl:variable name="vector1" select="parent::math:apply/*[2]"/>
  <xsl:variable name="vector2" select="parent::math:apply/*[3]"/>
  <xsl:text>magnitude(</xsl:text><xsl:value-of select="$vector1"/><xsl:text>)*magnitude(</xsl:text><xsl:value-of select="$vector2"/><xsl:text>)*Math.sin(</xsl:text><xsl:value-of select="$vector1"/><xsl:text>).angle(</xsl:text><xsl:value-of select="$vector2"/><xsl:text>)</xsl:text>
</xsl:template>

</xsl:stylesheet>
<?xml version="1.0"?>
<xsl:stylesheet  version="1.0" >
  <xsl:output method="text" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="math:mean">
  <xsl:variable name="array" select="parent::math:apply/*[2]"/>
     <xsl:text>mean(</xsl:text><xsl:value-of select="$array"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:variance">
  <xsl:variable name="array" select="parent::math:apply/*[2]"/>
     <xsl:text>variance(</xsl:text><xsl:value-of select="$array"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:sdev">
  <xsl:variable name="array" select="parent::math:apply/*[2]"/>
     <xsl:text>standardDeviation(</xsl:text><xsl:value-of select="$array"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:median">
  <xsl:variable name="array" select="parent::math:apply/*[2]"/>
     <xsl:text>median(</xsl:text><xsl:value-of select="$array"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:mode">
  <xsl:variable name="array" select="parent::math:apply/*[2]"/>
     <xsl:text>mode(</xsl:text><xsl:value-of select="$array"/>
     <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="math:moment">
  <xsl:variable name="array" select="parent::math:apply/*[4]"/>
  <xsl:variable name="p" select="parent::math:apply/*[3]"/>
  <xsl:variable name="degree" select="parent::math:apply/*[2]"/>
     <xsl:text>moment(</xsl:text><xsl:value-of select="$array"/><xsl:text>, </xsl:text><xsl:value-of select="$p"/><xsl:text>, </xsl:text><xsl:value-of select="$degree"/>
     <xsl:text>)</xsl:text>
</xsl:template>

</xsl:stylesheet>

Reply via email to