题
我最近将几个.xml文件从DocBook更改为DITA。转换还可以,但是有一些不必要的文物。我想的那个是.dita并没有重新调整 <para>
从docbook标记,并替换为 <p>
. 。您认为这会很好,但是这会导致XML在下一行中显示项目并订购的列表,即:
1 item One 2 item Two
代替:
1 item One 2 item Two
那么,我该如何更改:
<section>
<title>Cool Stuff</title>
<orderedlist>
<listitem>
<para>ItemOne</para>
</listitem>
<listitem>
<para>ItemTwo</para>
</listitem>
</orderedlist>
为此:
<section>
<title>Cool Stuff</title>
<orderedlist>
<listitem>
ItemOne
</listitem>
<listitem>
ItemTwo
</listitem>
</orderedlist>
对不起,我应该更清楚这个问题。我需要从doument中删除所有标签,这些标签的深度不同,但始终遵循(本地)树列表/para。我对此有些陌生,但是我可以通过将其插入我的DocBook2Dita转换来做错了。可以在那个地方吗?
解决方案
我会使用此样式表:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match ="listitem/para">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
笔记: :覆盖身份规则。 listitem/para
被绕过(这保存混合内容)
其他提示
您可以使用XSLT处理DITA文件 <para>
节点:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<!-- copy elements and attributes -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- replace para nodes within an orderedlist with their content -->
<xsl:template match ="orderedlist/listitem/para">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
我也有类似的问题,但是正在使用QTDOM,它并不总是像XSLT 2.x规格一样100%工作。 (我正在考虑在某个时候切换到Apache库...)
我想在DIV中更改我的代码中的等效“ ListItem”,其中包括相应的类:
<xsl:for-each select="/orderedlist/lisitem">
<div class="listitem">
<xsl:apply-templates select="node()"/>
</div>
</xsl:for-each>
这将删除ListItem并替换为u003Cdiv class="listitem">
然后模板,您拥有的u003Cpara>就我而言,可以包括标签,因此我无法使用其他两个将所有内容转换为纯文本的示例。相反,我使用了:
<xsl:template match ="para">
<xsl:copy-of select="node()"/>
</xsl:template>
这删除了“ para”标签,但保留了所有孩子。因此,段落可以包括格式,并在XSLT处理中保存。
不隶属于 StackOverflow