How can I count how many previous FootNoteReference nodes there are in an xml doc such as this…
<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>
Notice how the FootNoteReference node is nested at different levels. I know if they were all nested at the same level I could do: count(preceding-sibling::*[local-name() = 'FootNoteReference'])
Thanks!
Use the ‘
preceding‘ axis:count($vNode/preceding::FootNoteReference)is the number of
FootNoteReferenceelements that precede the node referenced by$vNode.If the node is a descendent of any
FootNoteReferenceelement and you want also to count its ancestorFootNoteReferenceelements, then the occurences of theFootNoteReferenceelement on the ‘ancestor‘ axis should also be accounted for, and this will be accomplished by the following XPath expression:count($vNode/preceding::FootNoteReference|$vNode/ancestor::FootNoteReference)