计算local-name()等于'FootNoteReference'的前一个元素

时间:2008-12-16 21:57:17

标签: xslt

如何计算xml文档中有多少个以前的 FootNoteReference 节点,例如...

<MyDoc>
<title>&lt;Big Title&gt;</title>
<head>Objective</head>
<head2>&lt;Heading&gt;</head2>
<head>Introduction</head>
<Para>
    asdf asdf asdf asd<FootNoteReference />asdf asdf asfd asfd 
</Para>
<head>Overview</head>
<Para>
    &lt;Begin with a definition of the class to which<FootNoteReference /> the categories belong, if required.&gt;
</Para>
<Para>&lt;List the different categories to be taught.&gt;</Para>
<Heading1>&lt;Category 1&gt;</Heading1>
<Para>&lt; som neodolal a celé ozdobené spústou prachu v jednom preso&gt;</Para>
<Para>&lt;Provide examples, if required.&gt;</Para>
<Heading1>&lt;Category 2&gt;</Heading1>
<Para>&lt; som neodolal a celé ozdobené spústou prachu v jednom preso&gt;</Para>
<Para>&lt;Provide examples, if required.&gt;</Para>
<Heading1>&lt;Category 3&gt;</Heading1>
<Para>
    &lt;Provide a description<FootNoteReference /> of the third category as outlined in the list.&gt;
</Para>
<Para>&lt;Provide examples, if required.&gt;</Para>
<head>Summary</head>
<ListItem type="ul">&lt;Summarize the definition, if applicable.&gt;</ListItem>
<ListItem type="ul">&lt; som neodolal a celé ozdobené spústou prachu v jednom preso<FootNoteReference />.&gt;</ListItem>
<ListItem type="ul">&lt; som neodolal a celé ozdobené spústou prachu v jednom preso&gt;</ListItem></MyDoc>

注意 FootNoteReference 节点如何嵌套在不同的级别。我知道它们是否都嵌套在我能做的同一级别:count(preceding-sibling::*[local-name() = 'FootNoteReference'])

谢谢!

1 个答案:

答案 0 :(得分:4)

使用"preceding" axis

<强> count($vNode/preceding::FootNoteReference)

FootNoteReference引用的节点之前的$vNode个元素的数量。

如果节点是任何FootNoteReference元素的后代,并且您还想计算其祖先FootNoteReference元素,那么the "ancestor" axisFootNoteReference元素的出现应该是也可以考虑,这将通过以下XPath表达式完成:

count($vNode/preceding::FootNoteReference
|
$vNode/ancestor::FootNoteReference)