i am trying to count the number of products for each zone "zona" . i want somthing like that :
Zona: 10 Num Productes: 4
Zona: 20 Num Productes: 3
Zona: 30 Num Productes: 4
Zona: 40 Num Productes: 2
but i am getting that :
Zona: 10 Num Productes: 0
Zona: 10 Num Productes: 0
Zona: 20 Num Productes: 0
Zona: 20 Num Productes: 0
Zona: 30 Num Productes: 0
Zona: 30 Num Productes: 0
Zona: 40 Num Productes: 0
I use that query:
for $prod in /productos/produc let $codi_prod:=$prod/cod_prod return {concat('Zona:',$prod/cod_zona,' ','Num Productes:',count($prod/codi_prod))}
the xml:
<productos>
<TITULO>DATOS DE LA TABLA PRODUCTOS</TITULO>
<produc>
<cod_prod>1010</cod_prod>
<denominacion>Placa Base MSI G41M-P26</denominacion>
<precio>50</precio>
<stock_actual>10</stock_actual>
<stock_minimo>3</stock_minimo>
<cod_zona>10</cod_zona>
</produc>
<produc>
<cod_prod>1011</cod_prod>
<denominacion>Micro Intel Core i5-2320</denominacion>
<precio>120</precio>
<stock_actual>3</stock_actual>
<stock_minimo>5</stock_minimo>
<cod_zona>10</cod_zona>
</produc>
<produc>
Use
for $zone in distinct-values(/productos/produc/cod_zona)
return concat('Zona:', $zone,' ','Num Productes:',count(/productos/produc[cod_zona = $zone]/codi_prod))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.