MFRACをMSUBの子孫として持つかどうかを確認することをお勧めします。 (一つの属性を挿入)MFENCEDを伸ばすために、以下のように述べ他の要素の最初または二番目の子孫の下に特定の子孫要素を見つける方法
ここではいくつかのシナリオ:MFRACが見出され、これはMSUB下にない場合
- は、その後ストレッチMFENCEDために必要
属性。 - MFRACがMFENCEDの子孫であり、 がMSUBのFIRST-CHILD-DESCENDANTで見つかった場合は、STRETCHが必要です。
- 入力xmlから3番目のMATHでは、2番目のMFENCEDはSTRETCHを要求しました.MSUBの2番目の子孫のMFRAC子孫ですが、そのMFENCED内では、MFRACは祖先としてMSUBを持っていません。
新規追加更なる説明:
下MFENCED
IF(から子孫(この)本MFENCED)任意MFRAC
見出され、次いでMFENCEDを伸ばすことができる、ここでMFENCE /祖先べきではない、なぜなら、主なMFENCEに関して、FRACはサブの下に2番目の子孫であった。明確でない場合、私はそれ以上の説明をします。
入力XML:
<article>
<math>
<mrow>
<mfenced open="(" close=")">
<!--stretch required -->
<mrow>
<mrow><mn>99999</mn></mrow>
<mrow>
<mrow><mn>9999</mn></mrow>
<mrow>
<mfenced open="(" close=")">
<!--stretch required -->
<mrow>
<mfrac><mi>a</mi><mi>b</mi></mfrac>
</mrow>
</mfenced>
</mrow>
</mrow>
</mrow>
</mfenced>
</mrow>
</math>
<math>
<mrow>
<mfenced open="(" close=")"><!--Stretch required, bcs descendant Frac, found as first child of msub, if descendant mfrac, found under (descendant) second child of MSUB, then no need to stretch-->
<mrow>
<mrow><mn>99999</mn></mrow>
<mrow>
<msub>
<mrow>
<mfenced open="(" close=")"><!--Stretch required, because under this mfen, 'mfrac' found under first child of 'msub' -->
<mrow>
<mfrac><mi>a</mi><mi>b</mi></mfrac>
</mrow>
</mfenced>
</mrow>
<mrow><mn>9999</mn></mrow>
</msub>
</mrow>
</mrow>
</mfenced>
</mrow>
</math>
<math>
<mrow>
<mfenced open="(" close=")"><!-- this mfence, no need to stretch, because, descendant MFRAC found under second child-descendant of MSUB -->
<mrow>
<mrow><mn>99999</mn></mrow>
<mrow>
<msub>
<mrow><mn>9999</mn></mrow>
<mrow>
<mfenced open="(" close=")"><!--Stretch required, because under this mfen, 'mfrac' found (even MFRAC under 2nd child-descendant of MSUB, but under existing MFENCE, MFRAC is not having ancestor MSUB -->
<mrow>
<mfrac><mi>a</mi><mi>b</mi></mfrac>
</mrow>
</mfenced>
</mrow>
</msub>
</mrow>
</mrow>
</mfenced>
</mrow>
</math>
</article>
XSLT 2.0:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:template>
<xsl:template match="mfenced">
<xsl:variable name="varFrac">
<xsl:for-each select="descendant::mfenced">
<xsl:for-each select="descendant::*[name()='mfrac']">
<xsl:choose>
<xsl:when test="not(ancestor::*[matches(name(), '^(msubsup|msub|msup|munder|munderover|mover|msqrt|mroot)$')]
[generate-id(ancestor::mmlmfenced[1])=generate-id(current()/ancestor::mmlmfenced[1])])">Yes2</xsl:when>
<xsl:when test="(ancestor-or-self::*/parent::*[not(preceding-sibling::*)]/parent::*[matches(name(), '^(msubsup|msub|msup|munder|munderover|mover|msqrt|mroot)$')]
[generate-id(ancestor::mmlmfenced[1])=generate-id(current()/ancestor::mmlmfenced[1])])">Yes21</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
<xsl:for-each select="descendant::*[name()='mfrac']">
<xsl:choose>
<xsl:when test="not(ancestor::*[matches(name(), '^(msubsup|msub|msup|munder|munderover|mover|msqrt|mroot)$')])">Yes1a</xsl:when>
<xsl:when test="(ancestor-or-self::*/parent::*[not(preceding-sibling::*)]/parent::*[matches(name(), '^(msubsup|msub|msup|munder|munderover|mover|msqrt|mroot)$')])">Yes11a</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains($varFrac, 'Yes')">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:attribute name="stretchy">true</xsl:attribute>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
必要な結果:
<article>
<math>
<mrow>
<mfenced open="(" close=")" stretchy="true">
<mrow>
<mrow>
<mn>99999</mn>
</mrow>
<mrow>
<mrow>
<mn>9999</mn>
</mrow>
<mrow>
<mfenced open="(" close=")" stretchy="true">
<mrow>
<mfrac>
<mi>a</mi>
<mi>b</mi>
</mfrac>
</mrow>
</mfenced>
</mrow>
</mrow>
</mrow>
</mfenced>
</mrow>
</math>
<math>
<mrow>
<mfenced open="(" close=")" stretchy="true">
<mrow>
<mrow>
<mn>99999</mn>
</mrow>
<mrow>
<msub>
<mrow>
<mfenced open="(" close=")" stretchy="true">
<mrow>
<mfrac>
<mi>a</mi>
<mi>b</mi>
</mfrac>
</mrow>
</mfenced>
</mrow>
<mrow>
<mn>9999</mn>
</mrow>
</msub>
</mrow>
</mrow>
</mfenced>
</mrow>
</math>
<math>
<mrow>
<mfenced open="(" close=")">
<mrow>
<mrow>
<mn>99999</mn>
</mrow>
<mrow>
<msub>
<mrow>
<mn>9999</mn>
</mrow>
<mrow>
<mfenced open="(" close=")" stretchy="true"><!-- Here stretch required -->
<mrow>
<mfrac>
<mi>a</mi>
<mi>b</mi>
</mfrac>
</mrow>
</mfenced>
</mrow>
</msub>
</mrow>
</mrow>
</mfenced>
</mrow>
</math>
</article>
先生、最後の点は、第二MFRACは、サブの第二子の子孫です。しかし、MFENCED(このMFENCE内のみ)では、MFRACはMSUBとして祖先を持っていないので、そのMFENCE内でチェックするためにgenerate-id()をコーディングしたのはなぜですか。提案してください。 –
すぐにあなたのコードの助けを借りて、助けてくれてありがとう。 –
XSLT 2.0では、 'generate-id($ X)= generate-id($ Y)'を '$ X is $ Y'として書き直すことができます。 –