Hello BaseX Staff,
I am trying to access members of a sequence that I have created already, but it whenever I use the functions subsequence() it returns the entire sequence, and count() always returns 1.
The code:
xquery version "3.1";
(
let $begin := db:open("CubeSatUML2.5XMIv3")/xmi:XMI/uml:Model/packagedElement
let $modelContent := $begin//packagedElement[@xmi:type="uml:Class"]
(: Combine the names of the elements with their ID's :)
let $names := $modelContent/@name
let $ids := $modelContent/@xmi:id
(: Grab all stereotypes, properties:[attributes, comments] :)
let $stereotypes := for $id in $ids
let $stereo1 := /xmi:XMI/*[@base_Element=$id]
let $stereo2 := /xmi:XMI/*[@base_Class=$id]
let $attributes := $begin//*[@xmi:id=$id]/ownedAttribute/[@name | @xmi:type | @xmi:id]
let $comments := $begin//*[@xmi:id=$id]/ownedComment/[@name | @xmi:type | @xmi:id | @body]
let $combined := ($id, $stereo1/name(), $stereo2/name(), $comments, $attributes, "")
return $combined
let $final :=
for $seq in $stereotypes
return subsequence($seq, 1, 1)
(: ^ the part in question:)
return $final
)
I realize I am creating this in a very weird way, but I want to keep the data together and have not thought of another solution.
I have tried 'for each'ing over the '$sequences' and tokenizing to get the elements out, but I get an error:
let $finalMap :=
for $seq in $stereotypes
return tokenize($seq, '\s')
[XPTY0004] Item expected, sequence found: ("uml:Property", "_18_5_2_4c1014b_153850....
When I print '$stereotypes', I get what appears to be a sequence of sequences (which I don't think is a real thing, but it appears to be that)
Ex output:
xmi:id="_18_5_2_4c1014b_1538500371989_609286_80522"
UAF:ResourceArtifact
[(xmi:type="uml:Property", xmi:id="_18_5_2_4c1014b_1538500468390_289646_80939", name="flight")]
[(xmi:type="uml:Property", xmi:id="_18_5_2_4c1014b_1538500488269_847951_81240", name="ground")]
xmi:id="_18_5_2_4c1014b_1538500376501_394659_80590"
UAF:ResourceArtifact
[(xmi:type="uml:Comment", xmi:id="_18_5_2_4c1014b_1538501028725_896600_82978", body="The ground supporting equipment and operations that support the spacecraft mission.")]
[(xmi:type="uml:Property", xmi:id="_18_5_2_4c1014b_1538500492755_533021_81326", name="ground Communications")]
[(xmi:type="uml:Property", xmi:id="_18_5_2_4c1014b_1538500495333_439654_81369", name="ground Command and Control")]
[(xmi:type="uml:Port", xmi:id="_18_5_2_4c1014b_1538582001724_435913_83660", name="Flight_Ground")]
My end goal is to have a map of maps, where the root map has keys of element names (currently in $names) and the value is a map of all the properties of this element.
To do this I have to deconstruct this monster I have created, and maybe I am on the wrong path entirely but some direction would be greatly appreciated.
End goal format:
map{
elementName : map {
stereotypes: map{
stereotype_Name_1: stereotype_ID_1,
stereotype_Name_2: stereotype_ID_2
},
attributeName: map{
'id': actual_ID_here,
'lowerValue': someValue,
'upperValue': "*"
},
comment: map{
'id': actual_ID_here,
'xmi:type': 'uml:Comment',
'body': actual_Comment_Here
},
'id': actual_ID_here
}
}
Thanks,
Jordan Castillo
</longWindedQuestion>