I have an XML like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<productos>
<TITULO>DATOS TABLA PRODUCTOS</TITULO>
<producto>
<cod_prod>1010</cod_prod>
<cod_zona>10</cod_zona>
</producto>
<producto>
<cod_prod>1011</cod_prod>
<cod_zona>10</cod_zona>
</producto>
<producto>
<cod_prod>1012</cod_prod>
<cod_zona>20</cod_zona>
</producto>
<producto>
<cod_prod>1612</cod_prod>
<cod_zona>30</cod_zona>
</producto>
</productos>
I need to group the products by zone.
With the instruction:
distinct-values( //producto/cod_zona )
I get:
10
20
30
I need to get the following:
Zona: 10
Zona: 20
Zona: 30
I'm testing with concat () but cardinality fails me, or does not group them, for example:
//producto/concat(
"Zona: ",
distinct-values( cod_zona/string( ))
)
produces the following output:
Zona: 10
Zona: 10
Zona: 20
Zona: 30
I need a way to do it in XPath, not XQuer-FLWOR:
for $zonas in doc("productos.xml")/distinct-values( //producto/cod_zona )
return concat(
"Zona: ",
$zonas
)
DOM, or others ... It has didactic purposes and only XPath is supported.