ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* How could I find the 'depth' of an element found with xml.first()?
@ 2020-06-18 13:24 Gerben Wierda
  2020-06-18 17:04 ` Hans Hagen
  0 siblings, 1 reply; 2+ messages in thread
From: Gerben Wierda @ 2020-06-18 13:24 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Given the following XML snippet

	<opa id=“opa">
		<Foo name="SubFoo Level One" id="Foo">
			<Foo name="SubFoo Level Two" id="Foo_2">
				<bar id="Bar" name="A Bar">
					<bar name="Bar Level Three" id="Bar_2">
						<Foo id="oma">OmaFoo</Foo>
					</bar>
				</bar>
				<Foo name="Fuzz Level Four" id="Fuzz"/>
			</Foo>
			<Foo name="SubFoo Level Two" id="Foo_3">
				<fuzz name="Fuzz" id="Fuzz_2"/>
			</Foo>
		</Foo>
	</opa>


How would I go about to find the depth of an item found with an LPATH? E.g.

//[id="Foo_3"] would find a node at depth 2 (assuming <opa> is at level 0) while //[id=“Fuzz_2"] would find a node at depth 3 and in either cases I would like to get that number (2 or 3) as well as the actual node. I can assume the values for ‘id’  are unique.

I was wondering how I could go about finding the ‘depth’ of an item in the XML when using the LMTX built-in functions to work with XML. I don’t think there is a default function for that, is there?

G
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-18 17:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-18 13:24 How could I find the 'depth' of an element found with xml.first()? Gerben Wierda
2020-06-18 17:04 ` Hans Hagen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).