【问题标题】:Conditional Formatting XSL条件格式 XSL
【发布时间】:2020-03-04 07:44:55
【问题描述】:

当我遇到<sup> 元素时,我正尝试将它们设为上标。我正在迭代一个大文件,如果需要,我可以包含它,基本上是<xml><article><body><p><em></em><sup></sup></p></body></article></xml>

我收到了:

XML 解析器报告的错误:元素类型“fo:inline”必须由 匹配的结束标签“</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 元素;有没有更好的方法呢?我计划稍后为ems 做同样的事情。

我目前使用的代码是:

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

【问题讨论】:

    标签: parsing xslt xml-parsing xslt-2.0


    【解决方案1】:

    如果您想将&lt;sup&gt;&lt;/sup&gt; 转换为&lt;fo:inline vertical-align='super' baseline-shift='4pt'&gt;&lt;/fo:inline&gt;,那么使用 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" 并在 xsl:apply-templates 上添加 mode="#current")。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-06
      • 2018-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-17
      相关资源
      最近更新 更多