如何计算xml文档中有多少个以前的 FootNoteReference 节点,例如...
<MyDoc>
<title><Big Title></title>
<head>Objective</head>
<head2><Heading></head2>
<head>Introduction</head>
<Para>
asdf asdf asdf asd<FootNoteReference />asdf asdf asfd asfd
</Para>
<head>Overview</head>
<Para>
<Begin with a definition of the class to which<FootNoteReference /> the categories belong, if required.>
</Para>
<Para><List the different categories to be taught.></Para>
<Heading1><Category 1></Heading1>
<Para>< som neodolal a celé ozdobené spústou prachu v jednom preso></Para>
<Para><Provide examples, if required.></Para>
<Heading1><Category 2></Heading1>
<Para>< som neodolal a celé ozdobené spústou prachu v jednom preso></Para>
<Para><Provide examples, if required.></Para>
<Heading1><Category 3></Heading1>
<Para>
<Provide a description<FootNoteReference /> of the third category as outlined in the list.>
</Para>
<Para><Provide examples, if required.></Para>
<head>Summary</head>
<ListItem type="ul"><Summarize the definition, if applicable.></ListItem>
<ListItem type="ul">< som neodolal a celé ozdobené spústou prachu v jednom preso<FootNoteReference />.></ListItem>
<ListItem type="ul">< som neodolal a celé ozdobené spústou prachu v jednom preso></ListItem></MyDoc>
注意 FootNoteReference 节点如何嵌套在不同的级别。我知道它们是否都嵌套在我能做的同一级别:count(preceding-sibling::*[local-name() = 'FootNoteReference'])
谢谢!
答案 0 :(得分:4)
<强> count($vNode/preceding::FootNoteReference)
强>
是FootNoteReference
引用的节点之前的$vNode
个元素的数量。
如果节点是任何FootNoteReference
元素的后代,并且您还想计算其祖先FootNoteReference
元素,那么the "ancestor
" axis上FootNoteReference
元素的出现应该是也可以考虑,这将通过以下XPath表达式完成:
count($vNode/preceding::FootNoteReference
|
$vNode/ancestor::FootNoteReference)