2017-03-28 1 views
0

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> 

답변

0

새로운 XSLT :

<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:choose><!--to check only within MFENCED descendant is MFRAC --> 
      <xsl:when test="descendant-or-self::*[matches(name(), '^(msubsup|msub|msup|munder|munderover|mover|msqrt|mroot)$')]/*[not(preceding-sibling::*)]/descendant::mfrac">Yes1</xsl:when> 
      <xsl:when test="descendant-or-self::*[matches(name(), '^(msubsup|msub|msup|munder|munderover|mover|msqrt|mroot)$')]/*[(preceding-sibling::*)]/descendant::mfrac">No1</xsl:when> 
      <xsl:when test="descendant-or-self::mfrac">Yes2</xsl:when> 
     </xsl:choose> 
     <!-- to check MFRAC found as online (first child-descendant of msub). --> 
     <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> 
1

MFRAC가 발견되었고 MSUB에 속하지 않은 경우 MFTENED 속성 STRETCH 이 필요합니다.

MFRAC는 자손과 같은 MFENCED MSUB의 FIRST-CHILD-하위하에 다음 필요한 연신 찾으면

<xsl:template match="mfenced[.//mfrac except .//msub//mfrac]"> 
    <xsl:copy> 
    <xsl:attribute name="stretchy">true</xsl:attribute> 
    <xsl:apply-templates select="@*, node()"/> 
    </xsl:copy> 
</xsl:template> 
.

입력 XML, 2 MFENCED 필요 STRETCH, MSUB의 두번째 하위 후손 심지어 MFRAC 자손에서 세번째 수학
<xsl:template match="mfenced[.//msub/*[1]//mfrac]"> 
    <xsl:copy> 
    <xsl:attribute name="stretchy">true</xsl:attribute> 
    <xsl:apply-templates select="@*, node()"/> 
    </xsl:copy> 
</xsl:template> 

하지만 MFENCED 내에 MFRAC 그 조상 MSUB 갖는되지와 .

죄송합니다. 여기에 귀하의 영어가 명확하지 않습니다.

+0

선생님, 마지막 포인트는, 2 MFRAC 하위의 둘째 아이의 자손이다. 그러나 MFENCED 내에서 (이 MFENCE 내에서만) MFRAC는 조상을 MSUB로 갖고 있지 않으므로 MFENCE 내에서 확인하려면 generate-id()를 코딩 한 것입니다. 제발 제안 해주세요. –

+0

곧 코드 선생님의 도움을 받으실 수 있으며 도움을 주셔서 감사합니다. –

+0

XSLT 2.0에서는'generate-id ($ X) = generate-id ($ Y)'를'$ X is $ Y'로 재 작성 할 수 있다는 점에 유의하십시오. –

관련 문제