Note that there are some explanatory texts on larger screens.

plurals
  1. POChild XML elements are not moving using XSLT
    text
    copied!<p>I am in need to move <code>&lt;sub&gt;</code>, <code>&lt;sup&gt;</code> elements as shown in the output. I could able to move the <code>&lt;sup&gt;</code> element. The child elements are not moving. I am also in need to rename the element as <code>&lt;msub&gt;</code> and <code>&lt;msup&gt;</code> accordingly. If I run XSLT twice, I could able to get the Output. But I dont want to do that. Kindly correct me where I made mistake. I should use XSLT1.0</p> <p>Input XML:</p> <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt; &lt;chapter xmlns="http://www.w3.org/1998/Math/MathML"&gt; &lt;math display="block"&gt; &lt;mfenced&gt; &lt;mrow&gt; &lt;mfrac&gt; &lt;mrow&gt; &lt;mi&gt;v&lt;/mi&gt; &lt;sub&gt; &lt;mrow&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt; &lt;/sub&gt; &lt;/mrow&gt; &lt;mrow&gt; &lt;mi&gt;v&lt;/mi&gt; &lt;sub&gt; &lt;mrow&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;/mrow&gt; &lt;/sub&gt; &lt;/mrow&gt; &lt;/mfrac&gt; &lt;/mrow&gt; &lt;/mfenced&gt; &lt;sup&gt;&lt;mrow&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/mrow&gt;&lt;/sup&gt; &lt;/math&gt; &lt;/chapter&gt; </code></pre> <p>Sample XSLT tried:</p> <pre><code>&lt;?xml version='1.0'?&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="@* | node()"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="self::*/following-sibling::*[1]/self::m:sub"&gt;&lt;/xsl:when&gt; &lt;xsl:when test="self::*/following-sibling::*[1]/self::m:sup"&gt;&lt;/xsl:when&gt; &lt;xsl:when test="self::*/following-sibling::*[1]/self::m:subsup"&gt;&lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@* | node()"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:template&gt; &lt;xsl:template match="m:sub"&gt; &lt;msub&gt; &lt;xsl:copy-of select="self::*/preceding-sibling::*[1]"/&gt; &lt;xsl:apply-templates/&gt; &lt;/msub&gt; &lt;/xsl:template&gt; &lt;xsl:template match="m:subsup"&gt; &lt;msubsup&gt; &lt;xsl:copy-of select="self::*/preceding-sibling::*[1]"/&gt; &lt;xsl:apply-templates/&gt; &lt;/msubsup&gt; &lt;/xsl:template&gt; &lt;xsl:template match="m:sup"&gt; &lt;msup&gt; &lt;xsl:copy-of select="self::*/preceding-sibling::*[1]"/&gt; &lt;xsl:apply-templates/&gt; &lt;/msup&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Required Output:</p> <pre><code>&lt;?xml version='1.0' ?&gt; &lt;chapter xmlns="http://www.w3.org/1998/Math/MathML"&gt; &lt;math display="block"&gt; &lt;msup&gt; &lt;mfenced&gt; &lt;mrow&gt; &lt;mfrac&gt; &lt;mrow&gt; &lt;msub&gt;&lt;mi&gt;v&lt;/mi&gt;&lt;mrow&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;/msub&gt; &lt;/mrow&gt; &lt;mrow&gt; &lt;msub&gt;&lt;mi&gt;v&lt;/mi&gt;&lt;mrow&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;/msub&gt; &lt;/mrow&gt; &lt;/mfrac&gt; &lt;/mrow&gt; &lt;/mfenced&gt; &lt;mrow&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/mrow&gt; &lt;/msup&gt; &lt;/math&gt; &lt;/chapter&gt; </code></pre>
 

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