I need to transform the XML element <mo> based on the character in it.
For example, if the element contains uppercase characters only, I need to transform as “obar”. But when it contains lower case characters only, I need to transform as “orule”. If the element contains both upper case and lower case characters then I need to transform as “obar”. Also if the element contains any of the ascender characters as given in XSLT code, it should be as “obar”.
I have used <xsl:if> condition. I need to use only one time of <xsl:if> condition
I need to transform by XSLT 1.0 only.
Sample XML Code:
<?xml version="1.0"?><chapter xmlns="http://www.w3.org/1998/Math/MathML">
<p>
<math display="block">
<mrow>
<mover accent='true'>
<mrow>
<mi>R</mi>
<mi>T</mi>
</mrow>
<mo stretchy='true'>¯</mo>
</mover>
<mover accent='true'>
<mrow>
<mi>a</mi>
<mi>A</mi>
</mrow>
<mo stretchy='true'>¯</mo>
</mover>
<mover accent='true'>
<mrow>
<mi>a</mi>
<mi>a</mi>
</mrow>
<mo stretchy='true'>¯</mo>
</mover>
<mover accent='true'>
<mrow>
<mi>a</mi>
<mi>h</mi>
</mrow>
<mo stretchy='true'>¯</mo>
</mover>
</mrow>
</math>
</p>
</chapter>
XSLT 1.0 tried:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1998/Math/MathML" xmlns:m="http://www.w3.org/1998/Math/MathML" >
<xsl:output method="xml" encoding="UTF-8" indent="no"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="m:mover[@accent='true']">
<xsl:choose>
<xsl:when test="(self::*/child::*[2]/self::m:mo[@stretchy='true']/text())='¯'">
<xsl:if test="(self::*/child::*[1]/self::m:mrow/child::*/text())='b' or 'd' or 'f' or 'h' or 'i' or 'j' or 'k' or 'l' or 'r' or 't' or 'A' or 'B' or 'C' or 'D' or 'E' or 'F' or 'G' or 'H' or 'I' or 'J' or 'K' or 'L' or 'M' or 'N' or 'O' or 'P' or 'Q' or 'R' or 'S' or 'T' or 'U' or 'V' or 'W' or 'X' or 'Y' or 'Z'"><xsl:text>*obar*{</xsl:text></xsl:if>
<xsl:if test="(self::*/child::*[1]/self::m:mrow/child::*/text())='a' or 'c' or 'e' or 'g' or 'm' or 'n' or 'o' or 'p' or 'q' or 's' or 'u' or 'v' or 'w' or 'x' or 'y' or 'z'"><xsl:text>*orule*{</xsl:text></xsl:if>
<xsl:apply-templates/>}</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="m:mrow"><xsl:apply-templates/></xsl:template>
<xsl:template match="m:mi"><xsl:apply-templates/></xsl:template>
<xsl:template match="m:mo"></xsl:template>
</xsl:stylesheet>
Output required:
<chapter xmlns="http://www.w3.org/1998/Math/MathML">
<p>
<math display="block">*obar*{RT}*obar*{aA}*orule*{aa}*obar*{ah}</math>
</p>
</chapter>
How’s this: