XSL:删除 xml 标签但保留其内容
我最近将几个 .xml 文件从 docbook 更改为 dita。转换顺利,但存在一些不需要的工件。我感到困惑的是 .dita 无法识别 docbook 中的
标签,并将其替换为
。您认为这很好,但这会导致 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>
抱歉,我应该把问题说得更清楚。我需要从文档中删除深度不同的所有标签,但始终遵循(本地)树 listitem/para 。我对此有点陌生,但是我可能会因为将其附加到我的 docbook2dita 转换而做错了。可以在那个地方吗?
I recently changed a couple of my .xml files from docbook to dita. The conversion went ok, but there are some unwanted artifacts. The one I'm stumped on is that .dita does not recongnize the <para>
tag from docbook, and replaces it with <p>
. Which you'd think would be fine, but this causes the XML to show items in and ordered list as being on the next line, i.e:
1 item One 2 item Two
instead of:
1 item One 2 item Two
so how do i change this:
<section>
<title>Cool Stuff</title>
<orderedlist>
<listitem>
<para>ItemOne</para>
</listitem>
<listitem>
<para>ItemTwo</para>
</listitem>
</orderedlist>
to this:
<section>
<title>Cool Stuff</title>
<orderedlist>
<listitem>
ItemOne
</listitem>
<listitem>
ItemTwo
</listitem>
</orderedlist>
I'm sorry, I should have been more clear with the question. I need to remove all tags from the doument which are at varying levels of depth, but always follow the (local) tree listitem/para . I'm a bit new to this, but could I could just be doing it wrong by tacking it on to my docbook2dita transformation. Can it be in that place?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会使用这个样式表:
注意:覆盖身份规则。
listitem/para
被绕过(这保留了混合内容)I would use this stylesheet:
Note: Overwrite identity rule.
listitem/para
are bypassed (this preserves mixed content)您可以使用过滤掉
节点的 XSLT 来处理 dita 文件:You can process the dita files with an XSLT that filters out the
<para>
nodes:我遇到了类似的问题,但我使用的是 QtDom,它并不总是像 XSLT 2.x 规范那样 100% 工作。 (我正在考虑在某个时候切换到 Apache 库...)
我想用相应的类更改 div 中代码中的等效“listitem”:
这将删除 listitem 并将其替换为
然后,模板(在我的例子中,中的内容)可以包含标签,因此我无法使用将所有内容转换为纯文本的其他两个示例。相反,我使用了它:
删除了“para”标签,但保持所有子项不变。因此段落可以包含格式,并且在 XSLT 处理过程中会保留格式。
I had a similar problem but am using QtDom which does not always work 100% like the XSLT 2.x specs. (I am thinking of switching to the Apache library at some point...)
I wanted to change the equivalent "listitem" in my code in a div with a corresponding class:
This removes the listitem and replaces it with <div class="listitem">
Then the template, what you have in <para>, in my case, can include tags, so I could not use the two other example that would transform everything into plain text. Instead I used that:
That removes the "para" tags, but keeps all the children as is. So paragraphs can include formatting and it is preserved across the XSLT processing.