XSL - 如何获取最近的前一个非空节点? [英] XSL - How to get the nearest preceding non-empty node?

查看:66
本文介绍了XSL - 如何获取最近的前一个非空节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

My XML

< / w:t><! -  7-36 | LTD_END  - > 

< w:p>
假设我住在w:p,我怎样才能确保非空节点之前的neare是评论?

解决方案

你能更具体地确定一个"非空节点"是什么吗?是什么?我可以将一个空元素节点定义为根本没有子节点的节点,但其他节点如注释节点或文本节点或处理指令节点在XPath数据模型中从不拥有任何子节点,但我不会将它们称为"空" ;


如果你想检查前面的兄弟节点是否是评论,那么请检查例如


< xsl:if test ="前同辈::节点()[1] [自::评论()]">


My XML

        </w:t><!--7-36|LTD_END-->
        
        <w:p>
Supposed I'm staying at w:p, how can I make sure that the neares preceding non-empty node is a comment?

解决方案

Can you be more specific as to what exactly a "non-empty node" is? I could define an empty element node to be one that has no child nodes at all but other nodes like comment nodes or text node or processing instruction nodes never have any child nodes in the XPath data model, nevertheless I would not call them "empty".

If you want to check that the immediately preceding sibling node is a comment then check e.g.

<xsl:if test="preceding-sibling::node()[1][self::comment()]">


这篇关于XSL - 如何获取最近的前一个非空节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆