【问题标题】:XSL: let raw HTML throughXSL:让原始 HTML 通过
【发布时间】:2010-01-29 14:25:01
【问题描述】:

我正在进行 XSL 转换。我正在转换的 XML 有一个包含 html 的节点。

<xml>
    <text>
        <p><b>Hello</b><em>There</em></p>
    </text>
</xml>

应用变换:

<xsl:template match="text">
    <div class="{name()} input">
        <xsl:value-of select="."/>
    </div>
</xsl:template>

我得到了输出:

<div class="text input">
    Hello There
</div>

但我希望 Html 像这样保持完整:

<div class="text input">
    <p><b>Hello</b><em>There</em></p>
</div>

node() 函数替换 . 会得到相同的结果。

有没有一种方法可以通过未修改的转换获取 HTML?

【问题讨论】:

    标签: html xslt


    【解决方案1】:

    看看xsl:copy-of

    它应该做你需要的..

    <xsl:copy-of select="." />
    

    上面将选择整个当前节点,因此在您的情况下,&lt;text&gt; 本身将被包括在内..

    使用以下选择当前..下的所有内容。

    <xsl:copy-of select="child::node()" />
    

    【讨论】:

    • &lt;xsl:copy-of select="." /&gt; 将复制整个 &lt;text&gt; 节点,而不仅仅是其内容。 ;)
    • 顺便说一句:子轴是隐式的。这意味着&lt;xsl:copy-of select="child::node()" /&gt;&lt;xsl:copy-of select="node()" /&gt; 是等价的。
    • 别忘了设置输出方法="html - 否则你可能得不到想要的结果。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-13
    • 2015-06-30
    • 2012-06-14
    • 2014-08-16
    • 2015-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多