【发布时间】:2012-11-29 23:12:16
【问题描述】:
鉴于下面的 XSL 模板和 XML,这是我试图实现的 HTML 输出(或多或少):
<p>
foo goes here
<span class="content"><p>blah blah blah</p><p>blah blah blah</p></span>
bar goes here
<span class="content">blah blah blah blah blah blah</span>
</p>
以下是实际渲染的内容(
<p>
foo goes here
<span class="content"></span>
bar goes here
<span class="content">blah blah blah blah blah blah</span>
</p>
这是我的模板 (sn-p):
<xsl:template match="note[@type='editorial']">
<span class="content">
<xsl:apply-templates />
</span>
</xsl>
<xsl:template match="p">
<p>
<xsl:apply-templates />
</p>
</xsl>
这是我的 xml:
<p>
foo goes here
<note type="editorial"><p>blah blah blah</p><p>blah blah blah</p></note>
bar goes here
<note type="editorial">blah blah blah blah blah blah</note>
</p>
渲染特定元素并不重要。 即。我不在乎是否渲染了
或
或 ,只要没有丢失任何文本元素。
我想避免创建一个特定的规则来匹配“p/note/p”,假设 元素可以包含任意子元素。
我是 xsl 的菜鸟,所以任何额外的提示或指针都会很有帮助。
提前致谢。
【问题讨论】:
-
您没有在 XSL 尝试匹配的输入 XML 中显示
<note ...>标记。请编辑您的帖子并在输入中的正确位置提供<note>包装标签。 -
xml输入中有两个
元素,最后一个块引用。顶部的两个块是输出。