如何在'emph'中处理多重属性元件

时间:2017-06-15 06:30:06

标签: xml xslt

Input xml: <emph italic="yes" superscript="yes">nd</emph>

My XSL Code:
<xsl:template match="emph[normalize-space()]">
    <xsl:choose>
        <xsl:when test="lower-case(@italic)='yes'">
            <italic>
                <xsl:apply-templates/>
            </italic>
        </xsl:when>
        <xsl:when test="lower-case(@superscript)='yes'">
            <sup>
                <xsl:apply-templates/>
            </sup>
        </xsl:when>
        <xsl:otherwise/>
    </xsl:choose>
</xsl:template>

使用我的xsl代码输出,但根据以下所需的outpu,我没有得到正确的输出:     <italic>nd</italic>

Required Output:
<italic><sup>nd</sup></italic>

1 个答案:

答案 0 :(得分:0)

XSLT 2.0 next-match is ideal for this:

<xsl:template match="emph" mode="render" priority="3">
  <italic>
    <xsl:next-match/>
  </italic>
</xsl:template>

<xsl:template match="*[@superscript='yes']" mode="render" priority="2">
  <sup>
    <xsl:next-match/>
  </sup>
</xsl:template>

<xsl:template match="*" mode="render" priority="1">
  <xsl:value-of select="."/>
</xsl:template>

and of course you can add other rules for other attributes.

相关问题