From: Gerben Wierda <gerben.wierda@rna.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: How could I find the 'depth' of an element found with xml.first()?
Date: Thu, 18 Jun 2020 15:24:26 +0200 [thread overview]
Message-ID: <6A3BBDEF-EE08-4749-8FD9-7E35FB928199@rna.nl> (raw)
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
___________________________________________________________________________________
next reply other threads:[~2020-06-18 13:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-18 13:24 Gerben Wierda [this message]
2020-06-18 17:04 ` Hans Hagen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6A3BBDEF-EE08-4749-8FD9-7E35FB928199@rna.nl \
--to=gerben.wierda@rna.nl \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).