【问题标题】:Strong tag in XML to XSLT transofrmation [closed]XML 到 XSLT 转换中的强标记 [关闭]
【发布时间】:2012-12-21 08:03:16
【问题描述】:

我有一个这样的 XML:

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

我应用 XSLT 转换来获取 HTML 文件,但生成的 HTML 未标记为 &lt;strong&gt;,我将其放入 XML 中。文本“非常重要的文本”显示正确,但没有被标签&lt;strong&gt;包裹。

为什么?

如何使标签出现&lt;strong&gt; 到达生成的 HTML 文件?

【问题讨论】:

  • 也许您应该向我们展示您的 xslt 转换...
  • 问题不完整,不贴XSLT代码!
  • 听起来您在需要copy-ofapply-templates 的地方使用了&lt;xsl:value-of&gt;,但如果没有看到当前代码,就不可能更具体。

标签: html xml xslt xml-parsing


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多