背景
将文档从OpenOffice转换为DocBook格式。
问题
文件的部分内容包括:
<ul><li><ul><li><ul><li><p>...</p></li></ul></li></ul></li></ul>
而文件的其他部分包括:
<ul><li><p>...</p></li></ul>
我尝试使用来匹配最内部的ul
标签
<xsl:template match="xhtml:ul[not(child::xhtml:li/child::xhtml:ul)]">
...
</xsl:template>
但这并不匹配。以下表达式:
<xsl:template match="xhtml:ul">
将创建,如预期:
<itemizedlist>
<itemizedlist>
<itemizedlist>
...
</itemizedlist>
</itemizedlist>
</itemizedlist>
所需输出
无论ul
嵌套如何,所需的输出格式为:
<itemizedlist>
...
</itemizedlist>
问题
匹配最里面的子ul
节点的正确语法是什么?
想法
有几种方法可以解决这个问题:
- 搜索/替换原始文档(只有大约20个实例)
- 在
li
节点中使用xsl:test
查看子节点是否为ul
什么XPath表达式可以工作?例如:
<xsl:template match="xhtml:ul[not(grandchild::xhtml:ul)]">
谢谢!
<xsl:template match="xhtml:ul[not(descendant::xhtml:ul)]">
<itemizedlist><xsl:apply-templates /></itemizedlist>
</xsl:template>