the implicit context of position

Thursday, 30 June 2022 · 5 messages
MH
Martin Honnenin reply to Graydon Saunders, 30 Jun 2022, 19:2130 Jun 2022 17:26 #
Quoted text · Graydon Saunders · 20 lines
Am 30.06.2022 um 17:21 schrieb Graydon Saunders: > Hello -- > > I've got an element node that's part of a document. I need its > position among the element children of its parent. > > $step/position() will (correctly!) always return 1, there's one thing > in $step, of course it does. > > replace($step/path(),'^.*\[(\p{Nd}+)\]$','$1') => xs:integer() > > gets me the implicit position but is something of a horror. > > for $e at $in in $step/../* where $e is $step return $in > > works, too, but any notion of elegance and clarity have fled screaming > into the night. > > I keep thinking there must be a better way; anyone got any suggestions? >
I think functx has some node-index-of you could use or use e.g.
   index-of($step/../*/generate-id(), generate-id($step))
HR
Hans-Juergen Rennauin reply to Graydon Saunders, 30 Jun 2022, 19:2130 Jun 2022 17:31 #
Hi Graydon, probably I misunderstand you, but isn't $node/count(preceding-sibling::*) + 1 what you need?Kind regards, Hans-Jürgen Am Donnerstag, 30. Juni 2022, 17:21:34 MESZ hat Graydon Saunders <graydonish at gmail.com> Folgendes geschrieben: Hello -- I've got an element node that's part of a document. I need its position among the element children of its parent. $step/position() will (correctly!) always return 1, there's one thing in $step, of course it does. replace($step/path(),'^.*\[(\p{Nd}+)\]$','$1') => xs:integer() gets me the implicit position but is something of a horror. for $e at $in in $step/../* where $e is $step return $in works, too, but any notion of elegance and clarity have fled screaming into the night. I keep thinking there must be a better way; anyone got any suggestions? Thanks!Graydon
CG
Christian Grünin reply to Graydon Saunders, 30 Jun 2022, 19:2130 Jun 2022 17:32 #
I’d probably do this: count($step/preceding-sibling::*) + 1
CG
Christian Grün30 Jun 2022 17:33 #
… or I’d probably simply listen to Hans-Jürgen ;)
Quoted text · Christian Grün · 6 lines
On Thu, Jun 30, 2022 at 5:32 PM Christian Grün <christian.gruen at gmail.com> wrote: > > I’d probably do this: > > count($step/preceding-sibling::*) + 1
GS
Graydon Saunders30 Jun 2022 19:21 #
Hello -- I've got an element node that's part of a document. I need its position among the element children of its parent.
$step/position() will (correctly!) always return 1, there's one thing in
$step, of course it does.
replace($step/path(),'^.*\[(\p{Nd}+)\]$','$1') => xs:integer() gets me the implicit position but is something of a horror.
for $e at $in in $step/../* where $e is $step return $in
works, too, but any notion of elegance and clarity have fled screaming into the night. I keep thinking there must be a better way; anyone got any suggestions? Thanks! Graydon

⚡Generated with XQuery