0
请建议,如何找到'mfrac'出现在其第二个子元素的'msup'元素下。 (Mfenced是mfenced,当它包含“mfrac作为它的后代,但只有当 mfrac下MSUP的老二位置找到,则应该转换为” 莫”。)如何识别特定元素下存在的元素与特定位置
- 当mfrac距离第一'msup'的孩子侧,那么'mfenced'是没有 需要改变。
- 当mfrac是老二内“MSUP”,然后“mfenced”的侧 是转换为“莫”
- 否则“mfrac”内“mfenced”发现,然后“mfenced”没有需要 来改变。
XML:
<article>
<math><mfenced open="(" close=")"><mfrac><mn>1</mn><mn>2</mn></mfrac></mfenced></math>
<math><mfenced open="(" close=")"><msup><mfrac><mn>1</mn><mn>2</mn></mfrac><mn>7</mn></msup></mfenced></math>
<math><mfenced open="(" close=")"><msup><mn>7</mn><mfrac><mn>1</mn><mn>2</mn></mfrac></msup></mfenced></math>
<math><mfenced open="(" close=")"><msup><mrow><mn>7</mn></mrow><mrow><mfrac><mn>1</mn><mn>2</mn></mfrac></mrow></msup></mfenced></math>
</article>
XSLT:
<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="mfenced">
<xsl:choose>
<xsl:when test="not(descendant::mfrac[. is ancestor::msup[1]/*[1]/descendant::*])"><!--checking, whether mfrac not found within first child of 'msup' -->
<mo><xsl:apply-templates/></mo>
</xsl:when>
<xsl:otherwise>
<xsl:copy><xsl:apply-templates select="@* | node()"/></xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
要求的结果:
<article>
<math><mfenced open="(" close=")"><mfrac><mn>1</mn><mn>2</mn></mfrac></mfenced></math><!--no need alter, because 'mfrac' found within 'mfenced'-->
<math><mfenced open="(" close=")"><msup><mfrac><mn>1</mn><mn>2</mn></mfrac><mn>7</mn></msup></mfenced></math><!--no need alter, because 'mfrac' found within first child of 'msup' -->
<math><mo><msup><mn>7</mn><mfrac><mn>1</mn><mn>2</mn></mfrac></msup></mo></math><!--Converted to 'MO', because 'mfrac' is under 2nd child of 'msup' -->
<math><mo><msup><mrow><mn>7</mn></mrow><mrow><mfrac><mn>1</mn><mn>2</mn></mfrac></mrow></msup></mo></math><!--Converted to 'MO', because 'mfrac' is under 2nd child of 'msup' -->
</article>
错误消息:
XPTY0004: A sequence of more than one item is not allowed as the second operand of 'is' (<mn/>, <mn/>)
感谢您的建议,但我可以有内相同的条件下 '**的xsl:当**',因为一些其他条件在选择内给出。 –
当然,我不明白为什么不。但我的建议是为其他条件创建模板,您现在有一个“”。 –
Tomalak
感谢您的建议,加上一个。 –