条件格式 XSL

Conditional Formatting XSL

我正在尝试让 <sup> 元素在遇到它们时带有上标。我正在遍历一个大文件,如果需要我可以包含它,基本上 <xml><article><body><p><em></em><sup></sup></p></body></article></xml>

我收到:

Error reported by XML parser: The element type "fo:inline" must be terminated by the matching end-tag "</fo:inline>"

当尝试使用以下提高上标时:

<xsl:for-each select="*">
    <fo:block>
        <xsl:if test="name() = 'sup'">
            <fo:inline vertical-align='super' baseline-shift='4pt'>
        </xsl:if>
        <xsl:apply-templates select="." mode="xhtml"/>
        <xsl:if test="name() = 'sup'">
            </fo:inline>
        </xsl:if>
    </fo:block>
</xsl:for-each>

如何更正此问题,使 vertical-align='super' 仅适用于 sup 元素;有更好的方法吗?我计划在 em 秒后做同样的事情。

我目前使用的代码是:

<xsl:for-each select="*">
    <fo:block><xsl:apply-templates select="." mode="xhtml"/></fo:block>
</xsl:for-each>

如果您想将 <sup></sup> 转换为 <fo:inline vertical-align='super' baseline-shift='4pt'></fo:inline>,那么使用 XSLT 的常用方法是设置一个模板

<xsl:template match="sup">
  <fo:inline vertical-align='super' baseline-shift='4pt'>
    <xsl:apply-templates/>
  </fo:inline>
</xsl:template>

我不确定你是想在一般情况下还是在特定模式下这样做(在那种情况下,在 xsl:template 上添加 mode="mode-name",在 [=16 上添加 mode="#current" =]).