Support Forum

Ask questions and get help from MobileTogether experts.
MobileTogether Product Information
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
View
Go to last post Go to first unread
devonnije  
#1 Posted : Wednesday, December 28, 2022 6:25:05 PM(UTC)
devonnije

Rank: Newbie

Groups: Registered
Joined: 12/28/2022(UTC)
Posts: 2
United Kingdom

I have two repeating XML trees. One is used to create a repeating row table. One of the repeated values is called "STN" and this display correctly in a lable on each repeating row ... different value each time as I'd expect.

I want to use the value of "STN" to index into another repeating tree, to update another label on the repeating row.

If (say) the value of STN is 23 for a given row, then indexing into the 2nd tree with [23] works fine, but if I replace the [23] with [STN] I get nothing. If I specify STN from it's Root, then the index value used is always 1 (which I'd expect).

I think that the 2nd tree changes/resets the context set by the repeating row, and [STN] therefore resolves to nothing (but no error) - so perhaps I need to write some other node with value of "STN" - and then use that other node to select from the 2nd tree?

Any comments apprecaited - as I say - I hope I'm not being daft.
ELP  
#2 Posted : Monday, January 2, 2023 10:09:23 AM(UTC)
ELP

Rank: Newbie

Groups: Registered
Joined: 10/7/2021(UTC)
Posts: 8
Austria

Was thanked: 1 time(s) in 1 post(s)
Hi!

I think what you need to use instead of [STN] is [xs:int(current())]. Please see attached solution file as we tried to reproduce your description.
File Attachment(s):
support-xml-indexing.mtd (3kb) downloaded 10 time(s).
devonnije  
#3 Posted : Monday, January 9, 2023 11:07:15 PM(UTC)
devonnije

Rank: Newbie

Groups: Registered
Joined: 12/28/2022(UTC)
Posts: 2
United Kingdom

elp - Thanks for your reply. It's not quite what I'm trying to acheive. The attached design file and XMLs are perhaps a better example. I want the combo box to only list those [XML1] "people" who's "typenum" equals the Nth entry in XML2 where that XML2 entry also has it's "select" set to one.

Hope you don't mind helping - I sense it's a reasonably basic thing to do, but my Assembler/Forth programming head just can't get it'self into the XML groove.
File Attachment(s):
PEOPLE.zip (2kb) downloaded 8 time(s).
AFC  
#4 Posted : Thursday, January 12, 2023 1:19:22 PM(UTC)
AFC

Rank: Administration

Groups: Registered, Administrators
Joined: 9/15/2014(UTC)
Posts: 140
Austria

Was thanked: 18 time(s) in 18 post(s)
Hi!

If I understand correctly and you really want to use indexes (positions), you should be able to use something like:
Quote:
for $p in $XML1/PEOPLE/PERSON
return if ( $XML2/TYPES/TYPE[xs:integer($p/TYPENUM)]/SELECT='1') then $p/NAME else ()


If you have big XML trees with many elements, you can also build a map at the beginning for faster execution, e.g.:
Quote:
let $m := map:merge($XML2/TYPES/TYPE/map:entry(position(), SELECT ='1'))
return $XML1/PEOPLE/PERSON[map:get($m, xs:integer(TYPENUM))]/NAME


When trying out the attached sample, you will see a bug in your sample data: ‘Paul’ is handled as ‘Woman’ (because its TYPENUM is ‘2’ although its TYPE is 'BOY')
Depending on your real use case, it can also make sense to directly use the TYPE of the PERSONs to make the lookup in $XML2, e.g.:
Quote:
let $selected := $XML2/TYPES/TYPE[SELECT='1']/NAME
return $XML1/PEOPLE/PERSON[TYPE=$selected]/NAME


Unsure how the attached sample fits your original question, so please let us know if this helps.
Users browsing this topic
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.