p & imag 移入 observ 元素 - XSLT

p & imag move into the observ element - XSLT

如何将p&imag元素移动到observ元素中?
输入XML:

    <root>
    <num>6</num>
        <imag>
            <apimag fic="[PHOTO]" scale="40"/>
        </imag>
        <qual>professeur a  l'universit</qual>
    <h1>Contentieux sur la validité du brevet</h1>
    <pnchr><observ/></pnchr>
    <p>Selon 1</p>
    <h2>Dalai de restauration</h2>
    <pnchr><observ/></pnchr>
    <p>Selon 2</p>
    <imag>
        <apimag fic="[PHOTO]" scale="40"/>
    </imag>
    <pnchr><observ/></pnchr>
    <p>Selon 3</p>
    <p>Selon 4</p>
</root>

预期输出:

    <root>
    <num>6</num>
    <imag>
        <apimag fic="[PHOTO]" scale="40"/>
    </imag>
    <qual>professeur a  l'universit</qual>
    <h1>Contentieux sur la validité du brevet</h1>
    <pnchr><observ>
        <p>Selon 1</p>
    </observ></pnchr>
    <h2>Dalai de restauration</h2>
    <pnchr><observ>
        <p>Selon 2</p>
        <imag>
            <apimag fic="[PHOTO]" scale="40"/>
        </imag>
    </observ></pnchr>
    <pnchr><observ>
        <p>Selon 3</p>
        <p>Selon 4</p>
    </observ></pnchr>
</root>

像这样:

<xsl:template match="root">
  <xsl:for-each-group select="*" group-starting-with="pnchr">
    <xsl:choose>
      <xsl:when test="self::pnchr">
        <pnchr><observ>
          <xsl:copy-of select="remove(current-group(),1)"/>
        </observ></pnchr>
      </xsl:when>
      <xsl:otherwise>
        <xsl:copy-of select="current-group()"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:for-each-group>
</xsl:template>