-2

我有一个这样的 XML:

<texto>
    <mytag>
        <es><strong>a very important text</strong> and other text</es>
    <mytag>
</texto>

我应用 XSLT 转换来获取 HTML 文件,但生成的 HTML 没有标记为<strong>我放入 XML 中。文本“一个非常重要的文本”正确显示,但它没有被标签包裹<strong>

为什么?

如何使标签出现<strong>在生成的 HTML 文件中?

4

1 回答 1

1

这是可以工作的 XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:template match="/">
        <xsl:apply-templates select="//es"/>
    </xsl:template>

    <xsl:template match="es">
        <xsl:apply-templates select="*|text()|@*"/>
    </xsl:template>

    <xsl:template match="*|text()|@*">
        <xsl:copy>
            <xsl:apply-templates select="*|text()|@*"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

输入文件:

<?xml version="1.0" encoding="UTF-8"?>
<texto>
    <mytag>
        <es><strong>a very important text</strong> and other text</es>
    </mytag>
</texto>

输出文件:

<strong>a very important text</strong> and other text
于 2012-12-21T11:02:26.637 回答