XML到XML的转换:消除元素外部的特定标点符号

时间:2013-12-14 11:59:45

标签: xml xslt-2.0

以下是我的xml文件中的代码段:

<citation citation-type="web">
<article-title>Dietary reference</article-title>. 
<publisher-name>The Academy</publisher-name>. 
<comment>Available from: 
<ext-link ext-link-type="uri">http://www.fap.com/catalog.php?</ext-link>
</comment>. 
<access-date>Accessed 2013</access-date>.
</citation>

我需要将其转换为以下内容:

<citation citation-type="web">
<article-title>Dietary reference</article-title>. 
<publisher-name>The Academy</publisher-name>. 
<comment>Available from: 
<ext-link ext-link-type="uri">http://www.fap.com/catalog.php?</ext-link>
Accessed 2013</comment>. 
</citation>

必须删除access-date元素,但其内容应放在comment元素内。但是,在执行此操作后,保留.之后的</access-date>。因此,</comment>之后现在有两个完整的止损。由于.位于access-date元素之外,我暂时陷入困境,我无法消除它。任何形式的帮助都将得到真正的赞赏。感谢。

1 个答案:

答案 0 :(得分:0)

根据您的评论,您只需添加一个空模板

<xsl:template match="citation/text()[preceding-sibling::node()[1][self::access-date] and normalize-space() = '.']"/>

确保不复制带有点.的第二个文本节点。