[xquery-talk] Generating an element sequence matching a template
Michael Kay
mhk at mhk.me.uk
Tue Apr 25 20:55:25 PDT 2006
Isn't it simply:
for $t in $template return
element {$t} { string($row-data[local-name()=$t]) }
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: talk-bounces at xquery.com
> [mailto:talk-bounces at xquery.com] On Behalf Of Howard Katz
> Sent: 25 April 2006 19:39
> To: talk at xquery.com
> Subject: [xquery-talk] Generating an element sequence
> matching a template
>
>
> Given a template of element names, I want to be able to write
> an XQuery function that takes that template, as well as a
> sequence of element nodes, and returns a "filled-out" list of
> elements where the template supplies the final length of the
> list and the names of empty elements to add to it if they're
> missing from the data. It's probably easier to provide an
> example than describe it.
>
> For example, given the data:
>
> let $template := ( "e_1", "e_2", "e_3", "e_1", "e_4" ) let
> $row-data := ( <e_1/>11</e_1>, <e_3>33</e_3>, <e_4>44</e_4> )
>
> I want the "fill-row-data( $template as xs:string+, $row-data
> as element()+ )" function to return this sequence:
>
> ( <e_1/>11</e_1>, <e_2/>, <e_3>33</e_3>, <e_1/>, <e_4>44</e_4> )
>
> The initial $row-data will contain some or all of the
> elements named in the template, and in the same order where
> present. The number of nodes in the final result will be the
> same as the number of names in the template. Where the
> element sequence has nodes corresponding to the template,
> those nodes are left as is. Where nodes that are named in the
> template are missing from the actual data, empty filler nodes
> are generated (eg <e_2/> and <e_1/>.
>
> The problem is motivated by a desire to produce an xhtml
> table where the list of <th> headers is fixed, but the actual
> data rows are sparse and heterogenous. I want to be able to
> generate homogenous rows so that the contents of each row
> exactly matches the given header.
>
> Howard
>
> _______________________________________________
> talk at xquery.com
> http://xquery.com/mailman/listinfo/talk
More information about the talk
mailing list