XSLT:建议使用其他代码,而所有';何时';不符合条件

XSLT:建议使用其他代码,而所有';何时';不符合条件,xslt,Xslt,请建议,我正在处理MathML代码,在'subsup'元素中,它应该有三个元素。但是我以前的脚本在'sub'或'subsup'元素之后插入了一些空格标记(这是内部进程所必需的)。到目前为止,现有的“subsup”将有三个以上的孩子。但是,我编写了所有条件,但如果不满足任何“时间”条件,则无法编写“否则”代码。如果找到空格,那么我的代码将用一个“mrow”括起“空格和后续或后续”,从而确保MSubup只有三个孩子 XML: 石墨烯 年份 H 1. 2. A. 1. 2. 2. B 1. 2. C

请建议,我正在处理MathML代码,在'subsup'元素中,它应该有三个元素。但是我以前的脚本在'sub'或'subsup'元素之后插入了一些空格标记(这是内部进程所必需的)。到目前为止,现有的“subsup”将有三个以上的孩子。但是,我编写了所有条件,但如果不满足任何“时间”条件,则无法编写“否则”代码。如果找到空格,那么我的代码将用一个“mrow”括起“空格和后续或后续”,从而确保MSubup只有三个孩子

XML:


石墨烯
年份
H
1.
2.
A.
1.
2.
2.
B
1.
2.
C
1.
7.
D
1.
2.
E
1.
2.

XSLT:


所需代码:请参阅我的xsl,建议使用“否则”代码。我使用的是XSL2版本

所需输出:

enter code here    <?xml version="1.0" encoding="UTF-8"?>
<article>
<body>
<p>Graphene <inline-formula>
<math>
<mtext>yyyy</mtext>
<msubsup>
  <mi>H</mi>
  <mn>1</mn>
  <mn>2</mn>
</msubsup>
<msubsup>
   <mrow>
    <mi>A</mi>
    <mspace width="0.04"/>
   </mrow>
   <mrow>
     <mn>1</mn>
     <mspace width="0.04"/>
   </mrow>
   <mrow>
    <mn>2</mn>
    <mspace width="0.04"/>
    <mspace width="0.04"/>
   <mn>2</mn>
   </mrow>
</msubsup>
<msubsup>
  <mi>B</mi>
  <mrow>
  <mn>1</mn>
  <mspace width="0.04"/>
  </mrow>
  <mrow>
  <mn>2</mn>
  <mspace width="0.04"/>
  </mrow>
</msubsup>
<msubsup>
<mi>C</mi>
<mn>1</mn>
<mrow>
<mn>7</mn>
<mspace width="0.04"/>
</mrow>
</msubsup>
<msubsup>
<mi>D</mi>
<mn>1</mn>
<mrow>
<mn>2</mn>
<mspace width="0.04"/>
</mrow>
</msubsup>
<msubsup>
<mrow>
<mi>E</mi>
<mspace width="0.04"/>
</mrow>
<mrow>
<mn>1</mn>
<mspace width="0.04"/>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</msubsup>
</math>
<inline-graphic xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="fdr495521ieqn220a39.gif"/>
</inline-formula>
</p>
</body>
</article>
在此处输入代码
石墨烯
年份
H
1.
2.
A.
1.
2.
2.
B
1.
2.
C
1.
7.
D
1.
2.
E
1.
2.


您能显示所需的XML输出吗?请参阅所需的输出文件(我编写的许多“when”条件),我的请求是,如果不满足任何when条件,那么该代码的“xsl:otherse”代码是什么。Subsup应该有三个子级,如果找到了mspace和第一个位置,那么,如果在第二个位置找到了mspace,那么mrow>,单词的第三个位置与其余元素一起,所有元素都位于第三个位置。
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="@*|node()">
       <xsl:copy>
           <xsl:apply-templates select="@* | node()"/>
       </xsl:copy>
    </xsl:template>
    <xsl:template match="msubsup[count(child::*) &gt; 3]">
      <xsl:element name="{name()}">
        <xsl:for-each select="*"><!--Cheking with each child, grouping mspace with preceded or followed element, ensuring three child with subsup element-->
           <xsl:choose>
              <xsl:when test="position()=1 and name()='mspace' and not(following-sibling::*[name()='mspace'])"><!--Child 1 having space, then it has to enclose by 'mrow' with immediate following element-->
                  <xsl:element name="mrow">
                       <xsl:apply-templates select="self::node()"/>
                      <xsl:apply-templates select="following-sibling::*[1]"/>
                  </xsl:element>
                  <xsl:apply-templates select="following-sibling::*[2]"/>
                  <xsl:apply-templates select="following-sibling::*[3]"/>
                  <xsl:apply-templates select="following-sibling::*[4]"/>
                  <xsl:apply-templates select="following-sibling::*[5]"/>
                  <xsl:apply-templates select="following-sibling::*[6]"/>
                  <xsl:apply-templates select="following-sibling::*[7]"/>
              </xsl:when>
              <xsl:when test="position()=2 and name()='mspace' and not(following-sibling::*[name()='mspace'])"><!--Child 2 having space, then it has to enclose by 'mrow' with immediate preceding element-->
                  <xsl:element name="mrow">
                      <xsl:apply-templates select="preceding-sibling::*"/>
                      <xsl:apply-templates select="self::node()"/>
                  </xsl:element>
                  <xsl:apply-templates select="following-sibling::*|node()"/>
              </xsl:when>
              <xsl:when test="position()=2 and name()='mspace' and following-sibling::*[2][name()='mspace']">
                  <xsl:element name="mrow">
                      <xsl:apply-templates select="preceding-sibling::*"/>
                      <xsl:apply-templates select="self::node()"/>
                  </xsl:element>
                  <xsl:element name="mrow">
                      <xsl:apply-templates select="following-sibling::*[1]"/>
                      <xsl:apply-templates select="following-sibling::*[2]"/>
                  </xsl:element>
                  <xsl:element name="mrow">
                      <xsl:apply-templates select="following-sibling::*[3]"/>
                      <xsl:apply-templates select="following-sibling::*[4]"/>
                      <xsl:apply-templates select="following-sibling::*[5]"/>
                      <xsl:apply-templates select="following-sibling::*[6]"/>
                      <xsl:apply-templates select="following-sibling::*[7]"/>
                  </xsl:element>
              </xsl:when>
              <xsl:when test="position()=2 and name()='mspace' and following-sibling::*[3][name()='mspace']">
                  <xsl:element name="mrow">
                      <xsl:apply-templates select="preceding-sibling::*"/>
                      <xsl:apply-templates select="self::node()"/>
                  </xsl:element>
                      <xsl:apply-templates select="following-sibling::*[1]"/>
                  <xsl:element name="mrow">
                      <xsl:apply-templates select="following-sibling::*[2]"/>
                      <xsl:apply-templates select="following-sibling::*[3]"/>
                      <xsl:apply-templates select="following-sibling::*[4]"/>
                      <xsl:apply-templates select="following-sibling::*[5]"/>
                      <xsl:apply-templates select="following-sibling::*[6]"/>
                      <xsl:apply-templates select="following-sibling::*[7]"/>
                  </xsl:element>
              </xsl:when>
              <xsl:when test="position()=3 and name()='mspace' and not(preceding-sibling::*[name()='mspace'])">
                  <xsl:apply-templates select="preceding-sibling::*[2]"/>
                  <xsl:element name="mrow">
                      <xsl:apply-templates select="preceding-sibling::*[1]"/>
                      <xsl:apply-templates select="self::node()"/>
                  </xsl:element>
                  <xsl:element name="mrow">
                      <xsl:apply-templates select="following-sibling::*|node()"/>
                  </xsl:element>
              </xsl:when>
              <xsl:when test="(position()=4 or position() &gt; 4) and name()='mspace' and not(preceding-sibling::*[name()='mspace'])">
                  <xsl:apply-templates select="preceding-sibling::*[3]"/>
                  <xsl:apply-templates select="preceding-sibling::*[2]"/>
                  <xsl:element name="mrow">
                      <xsl:apply-templates select="preceding-sibling::*[1]"/>
                      <xsl:apply-templates select="self::node()"/>
                      <xsl:apply-templates select="following-sibling::*|node()"/>
                  </xsl:element>
              </xsl:when>
              <!--Please suggest, what may be the 'otherwise' code if top all 'when' conditions not met-->
              <!--xsl:otherwise>
                   <xsl:apply-templates select="self::node()"/>
              </xsl:otherwise-->
          </xsl:choose>
      </xsl:for-each>
    </xsl:element>
   </xsl:template>
 </xsl:stylesheet>
enter code here    <?xml version="1.0" encoding="UTF-8"?>
<article>
<body>
<p>Graphene <inline-formula>
<math>
<mtext>yyyy</mtext>
<msubsup>
  <mi>H</mi>
  <mn>1</mn>
  <mn>2</mn>
</msubsup>
<msubsup>
   <mrow>
    <mi>A</mi>
    <mspace width="0.04"/>
   </mrow>
   <mrow>
     <mn>1</mn>
     <mspace width="0.04"/>
   </mrow>
   <mrow>
    <mn>2</mn>
    <mspace width="0.04"/>
    <mspace width="0.04"/>
   <mn>2</mn>
   </mrow>
</msubsup>
<msubsup>
  <mi>B</mi>
  <mrow>
  <mn>1</mn>
  <mspace width="0.04"/>
  </mrow>
  <mrow>
  <mn>2</mn>
  <mspace width="0.04"/>
  </mrow>
</msubsup>
<msubsup>
<mi>C</mi>
<mn>1</mn>
<mrow>
<mn>7</mn>
<mspace width="0.04"/>
</mrow>
</msubsup>
<msubsup>
<mi>D</mi>
<mn>1</mn>
<mrow>
<mn>2</mn>
<mspace width="0.04"/>
</mrow>
</msubsup>
<msubsup>
<mrow>
<mi>E</mi>
<mspace width="0.04"/>
</mrow>
<mrow>
<mn>1</mn>
<mspace width="0.04"/>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</msubsup>
</math>
<inline-graphic xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="fdr495521ieqn220a39.gif"/>
</inline-formula>
</p>
</body>
</article>