MFRAC를 MSUB의 자손으로 식별하는지 제안하십시오. 여기 다른 요소의 첫 번째 또는 두 번째 자손에서 발견 된 특정 자손 요소를 식별하는 방법
는 MFENCED (삽입 한 특성)을 신장 시키 후술 일부 시나리오 :- MFRAC 발견하고 MSUB 아니며, 이는 다음 MFENCED 필요한 STRETCH
속성 경우. - MSFR의 FIRST-CHILD-DESCENDANT에서 MFRAC이 MFENCED의 자손이며 인 경우 STRETCH가 필요합니다.
- 입력 xml의 세 번째 MATH에서 두 번째 MFENCED에 STRETCH가 필요합니다. MSUB의 두 번째 하위 자손의 MFRAC 자손이지만 해당 MFENCED 내에서 MFRAC는 조상으로 MSUB를 갖고 있지 않습니다.
새로 추가 된 추가 설명 :
아래 MFENCED
경우 (발 자손 (이) 본 MFENCED) 상관 MFRAC
발견하고 MFENCED 스트레칭 수 여기서 MFENCE/조상해서는 안 때문에, 주요 MFENCE와 관련하여 FRAC은 하위 두 번째 하위 - 자손 아래에 있습니다. 명확하지 않으면, 나는 더 설명 할 것이다.
입력 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>
선생님, 마지막 포인트는, 2 MFRAC 하위의 둘째 아이의 자손이다. 그러나 MFENCED 내에서 (이 MFENCE 내에서만) MFRAC는 조상을 MSUB로 갖고 있지 않으므로 MFENCE 내에서 확인하려면 generate-id()를 코딩 한 것입니다. 제발 제안 해주세요. –
곧 코드 선생님의 도움을 받으실 수 있으며 도움을 주셔서 감사합니다. –
XSLT 2.0에서는'generate-id ($ X) = generate-id ($ Y)'를'$ X is $ Y'로 재 작성 할 수 있다는 점에 유의하십시오. –