Based on this question additionally to the value of an argument I'm trying to extract the text of a node.
<parents name='Parents'>
<Parent id='1' name='Parent_1'>
<Children name='Children'>
<child name='Child_1' id='1'>child1_Parent_1</child>
<child name='Child_2' id='2'>child2_Parent_1</child>
<child name='Child_3' id='3'>child3_Parent_1</child>
<child name='Child_4' id='4'>child4_Parent_1</child>
</Children>
</Parent>
<Parent id='2' name='Parent_2'>
<Children name='Children'>
<child name='Child_1' id='8'>child1_parent2</child>
<child name='Child_2' id='7'>child2_parent2</child>
<child name='Child_4' id='6'>child4_parent2</child>
<child name='Child_3' id='5'>child3_parent2</child>
</Children>
</Parent>
</parents>
I would like to get this output when I run a match-query with "child1":
Parent_1
child1_Parent_1
Querying for two values at once
This query:
//Parent[@id='1']/Children/child[text()[matches(.,"^child1","i")]]/(text()|../../@name)
yields:
{}name="Parent_1"
child1_Parent_1
Which comes close to the result I'm looking for. But I would like the clean attribute-value, without the attribute-name.
Clean Attribute-value with xs:string
This can be done with a string-cast:
//Parent[@id='1']/Children/child[text()[matches(.,"^child1","i")]]/xs:string(../../@name)
which gives me a clean attribute-value:
Parent_1
A combination of both queries?
I would imagine it should be possible to combine these two queries:
//Parent[@id='1']/Children/child[text()[matches(.,"^child1","i")]]/(text()|xs:string(../../@name))
but that results in an error which I don't understand:
stdin:26: query failed, Error: Sequence does not match type node()* - found item of type {http://www.w3.org/2001/XMLSchema}string [err:XPTY0004]
I've tried different ways to combine the query, but none of them work. I'm using the dbxml-shell in Berkeley DB XML for testing.