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 - Unusual behaviour when drawing lots of images onto a large canvas -

how can i manage url using .htaccess in php? -

javascript - Chart.js - setting tooltip z-index -