Consider previous items that have a local name () equal to 'FootNoteReference'

How to count the number of previous FootNoteReference nodes in an XML document like ...

<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>

      

Note that the FootNoteReference node is nested at different levels. I know if they are all nested at the same level as me:count(preceding-sibling::*[local-name() = 'FootNoteReference'])

Thank!

+1


source to share


1 answer


Use the " preceding

" axis
:

        count($vNode/preceding::FootNoteReference)

- the number of elements FootNoteReference

that precede the node being referenced $vNode

.



If node is a descendant of any element FootNoteReference

, and you also want to count its parent elements FootNoteReference

, then the occurrences of the element are FootNoteReference

on the " ancestor

" axis
, and this will be done with the following XPath expression:

      count($vNode/preceding::FootNoteReference


            |


            $vNode/ancestor::FootNoteReference)

+4


source







All Articles