【发布时间】:2017-07-31 16:02:37
【问题描述】:
我的输入有一些我想修复的不合格标记,例如
<ul>
<li>
</li>
<p>This is the first bullet item</p>
<li>
</li>
<p>This is the second bullet item</p>
</ul>
...
<ul>
<li>I am fine. No need to monkey with me.</li>
<ul>
应该是
<ul>
<li>This is the first bullet item</li>
<li>This is the second bullet item</li>
</ul>
...
<ul>
<li>I am fine. No need to monkey with me.</li>
<ul>
我知道如何“解开”p 元素
<xsl:template match="p[parent::ul and preceding-sibling::li]">
<!-- Don't wrap or copy. Just process content. -->
<xsl:apply-templates/>
</xsl:template>
但我不知道如何让解包的ps 的内容出现在输出的lis 中。不知何故,我猜,我需要识别空的lis,而不是创建一个新的li,然后添加以下兄弟p 的内容。类似的东西
<xsl:template match="li[not(li) and not(normalize-space())]">
<li>
<!-- how do I get content of following-sibling p here?? -->
<xsl:apply-templates/>
</li>
</xsl:template>
但这(显然)不起作用。我被卡住了,找不到解决方案。有什么建议吗?
【问题讨论】: