<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:pf="http://www.daisy.org/ns/pipeline/functions" xmlns:m="http://www.w3.org/1998/Math/MathML" version="2.0" exclude-result-prefixes="#all">
<xsl:function xmlns:MathMLToSSML="org.daisy.pipeline.mathml.tts.saxon.impl.MathMLToSSMLFunctionProvider$MathMLToSSML" name="pf:mathml-to-ssml" as="element()?">
<xsl:param name="mathml" as="element(m:math)"/>
<xsl:param name="language" as="xs:string"/>
<xsl:variable name="ssml" select="MathMLToSSML:transform($mathml,$language)">
</xsl:variable>
<xsl:sequence select="if ($ssml instance of document-node()) then $ssml/* else $ssml"/>
</xsl:function>
<xsl:template match="*[@xml:lang|@lang]" priority="1">
<xsl:next-match>
<xsl:with-param name="lang" tunnel="yes" select="string((@xml:lang,@lang)[1])"/>
</xsl:next-match>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="m:math[@id]" priority="1.1">
<xsl:param name="lang" tunnel="yes" as="xs:string" select="'und'"/>
<xsl:variable name="mathml" as="element()" select="."/>
<xsl:variable name="ssml" as="element()?" select="pf:mathml-to-ssml(.,(@xml:lang/string(.),$lang)[1])"/>
<xsl:choose>
<xsl:when test="$ssml/@id[string(.)=string($mathml/@id)] and ($ssml/@xml:lang/string(.),$lang)[1]=(@xml:lang/string(.),$lang)[1]">
<xsl:sequence select="$ssml"/>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$ssml">
<xsl:copy>
<xsl:sequence select="$mathml/(@id,@xml:lang)"/>
<xsl:apply-templates select="(@* except @id|@xml:lang)|node()"/>
</xsl:copy>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>