[ZPT] Creating a XML resultset using ZPT?

Luis Lavena luislavena@hotmail.com
Mon, 25 Mar 2002 12:59:21 -0300


Cassey: I have a table with a filed as SlideID, that field is used to filter
on the ZSQLMethod only the records that belong to the slide.

SlideID, ParamName, ParamType, ParamValue are the fields in the table.

when I call the selectSlideParams pass the SlideID as param, and the resul
must be formatted to comply with XML (wich will be used from Flash, who
originally call it).

One solution, the best I think, is parse each row of the resultset, maybe
using print inside a Python Script.

I have resolved it, just for now (until have more time to optimize/play with
it) in this way:

<params tal:define="results here/selectSlideParams"
        tal:condition="results"><div tal:omit-tag=""
    tal:repeat="item results">
<tal:dummy tal:replace="structure
string:&lt;${item/ParamName}&gt;${item/ParamValue}&lt;/${item/ParamName}&gt;
" /></div></params>

I know it sounds ugly (not only sounds, it is indeed) :)

Using the "structure" I get the "<",">" and "</" of each XML tag.

Just a solution for now.

I think that using the ZPT to parse it cost more to the process, but will
need to think a better way during this week.

Thanks for your answer.

Luis

Casey Duncan wrote:
> From what I gather, each slide might have a different number of
> parameters? How is this working using only one table? Do you simply have
> a non-normal table with many columns, many of which are usually null? Or
> are there just multiple rows per slide?
>
> I'm going to assume the latter. In this case you will need to group on
> each distinct slide key value. dtml-in can do this, but AFIAK,
> tal:repeat cannot. however, it would be pretty easy to write a python
> script which does list grouping. Basically it would just nest lists
> together, like so (untested):
>
> rs = container.selectSlides(context.REQUEST)
> key = None
> result = []
> group = []
> for rec in rs:
>      if group and rec.slide_key_field != key:
>          result.append(group)
>          group = []
>      else:
>          group.append(rec)
>          key = rec.slide_key_field
>
> if group:
>      result.append(group)
>
> return result
>
> Then use two nested tal:repeats to generate your xml.
>
> hth,
>
> Casey