Clicky

I am very much a newbie to XQuery and would appreciate some help/guidance with this problem.
It is simplified in this example but it shows what I am trying to achieve.

I have a variable called $tempResult which contains
 <item value="BBB" num="72"/>
 <item value="DD" num="33"/>
 <item value="AAA" num="45"/>

Later I wish to return a result element like this
      return
      <result query="{$query}"
          customResult="QQQ"
      >


Where I have QQQ I would like some information obtained from $tempResult, so for this simplified example I would like the customResult attribute to contain this value
          customResult="AAA#45#BBB#72#DD#33#"

Basically concatenating the value and num attribute pairs found in $tempResult and putting them into the customResult attribute.
Ideally sorted by the value attribute as shown above.

asked 02/01/2011 06:26

Letterpart's gravatar image

Letterpart ♦♦


4 Answers:
try this
1:
2:
3:
4:
5:
6:
7:
8:
9:
let $querystr := 
    for $i in $query//item
    return 
        concat($i/@value, '##', $i/@num, '###')
    
return
     <result query="{$querystr}"
          customResult="QQQ"
      />
link
Gertone's gravatar image

Gertone

note that this is a bit nicer (but somewhat less control)
1:
2:
<result query="{string-join($query//item/@*, '##')}"
          customResult="QQQ" />
link
Gertone's gravatar image

Gertone

Excellent -  thanks for both of those solutions.
link
Letterpart's gravatar image

Letterpart

welcome
link
Gertone's gravatar image

Gertone

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×1

Asked: 02/01/2011 06:26

Seen: 448 times

Last updated: 02/02/2011 10:03