鉴于下面的 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>
这是我的模板(片段):
<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>
渲染特定元素并不重要。即。我不关心
或
我对 xsl 完全是个菜鸟,所以任何其他提示或指示都会非常有帮助。
提前致谢。
最佳答案
您应该使用apply-templates
而不是apply-template
:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="note[@type='editorial']">
<span class="content">
<xsl:apply-templates/>
</span>
</xsl:template>
<xsl:template match="p">
<p>
<xsl:apply-templates />
</p>
</xsl:template>
</xsl:stylesheet>
关于html - XSLT 和嵌套元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13636504/