Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If I understood you correctly, what you're trying to do is</p> <ol> <li>for any <code>sub</code> or <code>sup</code> element, move its previous sibling (if any) inside the element and</li> <li>rename <code>sub</code> to <code>msub</code> and <code>sup</code> to <code>msup</code>.</li> </ol> <p>This XSLT should do the trick:</p> <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns="http://www.w3.org/1998/Math/MathML" exclude-result-prefixes="m"&gt; &lt;xsl:output method="xml"/&gt; &lt;xsl:template match="*[following-sibling::*[1]/self::m:sub]"&gt; &lt;msub&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@* | node()"/&gt; &lt;/xsl:copy&gt; &lt;xsl:apply-templates select="following-sibling::*[1]/self::m:sub/@* | following-sibling::*[1]/self::m:sub/node()"/&gt; &lt;/msub&gt; &lt;/xsl:template&gt; &lt;xsl:template match="*[following-sibling::*[1]/self::m:sup]"&gt; &lt;msup&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@* | node()"/&gt; &lt;/xsl:copy&gt; &lt;xsl:apply-templates select="following-sibling::*[1]/self::m:sup/@* | following-sibling::m:sup/node()"/&gt; &lt;/msup&gt; &lt;/xsl:template&gt; &lt;xsl:template match="m:sub | m:sup"&gt;&lt;/xsl:template&gt; &lt;xsl:template match="@* | node()"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@* | node()"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>The only thing that's not clear to me is what to do this <code>sub</code> (<code>sup</code>) elements that have no preceding sibling. The code above just ignores them.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload