+ else if (o->direction == ODR_DECODE)
+ {
+ Z_FacetList *fl = (Z_FacetList *) odr_malloc(o, sizeof(*fl));
+ xmlNode *p1;
+
+ fl->num = 0;
+ for (p1 = n->children; p1; p1 = p1->next)
+ if (yaz_match_xsd_element(p1, "facet"))
+ fl->num++;
+ if (fl->num > 0)
+ {
+ int i = 0;
+ *facetList = fl;
+ fl->elements = (Z_FacetField **)
+ odr_malloc(o, sizeof(*fl->elements) * fl->num);
+ for (p1 = n->children; p1; p1 = p1->next)
+ if (yaz_match_xsd_element(p1, "facet"))
+ {
+ char *index_name = 0;
+ xmlNode *p_terms = 0;
+ xmlNode *p2 = p1->children;
+ Z_FacetField *ff = (Z_FacetField *)
+ odr_malloc(o, sizeof(*ff));
+ fl->elements[i++] = ff;
+ ff->attributes = 0;
+ ff->num_terms = 0;
+ ff->terms = 0;
+ for (; p2; p2 = p2->next)
+ {
+ if (yaz_match_xsd_string(p2, "index", o, &index_name))
+ ;
+ else if (yaz_match_xsd_element(p2, "terms"))
+ p_terms = p2;
+ }
+ if (index_name)
+ ff->attributes =
+ zget_AttributeList_use_string(o, index_name);
+ if (p_terms)
+ {
+ xmlNode *p;
+ int i = 0;
+ for (p = p_terms->children; p; p = p->next)
+ {
+ if (yaz_match_xsd_element(p, "term"))
+ ff->num_terms++;
+ }
+ if (ff->num_terms)
+ ff->terms = (Z_FacetTerm **)
+ odr_malloc(o,
+ sizeof(*ff->terms) * ff->num_terms);
+ for (p = p_terms->children; p; p = p->next)
+ {
+ if (yaz_match_xsd_element(p, "term"))
+ {
+ char *cstr = 0;
+ Odr_int *count = 0;
+ xmlNode *p2 = p->children;
+ for (; p2; p2 = p2->next)
+ {
+ if (yaz_match_xsd_string(p2, "actualTerm", o,
+ &cstr))
+ ;
+ else if (yaz_match_xsd_integer(p2, "count", o,
+ &count))
+ ;
+ }
+ if (cstr && count)
+ {
+ ff->terms[i++] =
+ facet_term_create_cstr(o, cstr, *count);
+ }
+ }
+ }
+ ff->num_terms = i;
+ if (ff->num_terms == 0)
+ ff->terms = 0;
+ }
+ }
+
+ }
+ }