Xquery - sequential number -


i have xml document following data. need display this. every new plant attribute called id should added display sequential number. first plant 1, second type of plant 2 , on. not sure start...any guidance appreciated.

<catalog> <plant> <common>abc</common> <botanical>mno</botanical> <zone>4</zone> <light>mostly shady</light> </plant> <plant> <common>pqr</common> <botanical>fgh</botanical> <zone>3</zone> <light>mostly shady</light> </plant> </catalog> 

output should :

<catalog> <plant id="1"> <common>abc</common> <botanical>mno</botanical> <zone>4</zone> <light>mostly shady</light> </plant> <plant  id="2"> <common>pqr</common> <botanical>fgh</botanical> <zone>3</zone> <light>mostly shady</light> </plant> </catalog> 

thanks help.

use positional var in flowr expression:

for $p @ $id in //plant return <plant id="{$id}">{$p/*}</plant> 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -