Liam,

Thanks for help,
Basex implements serialize function. This can do:

   let $params := <output:serialization-parameters xmlns:output="
http://www.w3.org/2010/xslt-xquery-serialization";>
                      <output:omit-xml-declaration value="yes"/>
                    </output:serialization-parameters>

    let $sf :=  fn:concat(fn:serialize(<h3>Features:</h3>,$params),
                        fn:serialize(<br/>,$params),
                        fn:serialize(
                            <ul>
                              <li>{$f1}</li>
                              <li>{$f2}</li>
                              <li>{$f3}</li>
                            </ul>,
                        $params))



On Mon, Dec 2, 2013 at 3:44 PM, Liam R E Quin <l...@w3.org> wrote:

> On Mon, 2013-12-02 at 15:29 -0500, Erol Akarsu wrote:
> > I would like to generate CDATA of one xmk construct like this.
> [...]
> > let $allfs := <record>
> >                       <name>{$name}</name>
> >                       <features>
> >                         <![CDATA[
> >                         <h3>Features:</h3>
> >                         <br/>
> >                         <ul>
> >                           <li>{$f1}</li>
> >                           <li>{$f2}</li>
> >                           <li>{$f3}</li>
> >                         </ul>
> >                         ]]>
> >                       </features>
> >                   </record>
>
> Watch out that if $f1 (say) contains the string ]]> you'd be liable to a
> cdata injection attack.
>
> Having said that, no, I'd probably write an e() function,
> declare function my:e($name as xs:string, $content as xs:string)
> as xs:string
> {
>   return concat("<", $name, ">", $content, "</", $name, ">")
> }
>
> and use my:e("ul",
>   concat(my:e("li", $f1),
>          my:e("li", $f2),
>          my:e("li", $f3))
> and so on. Which gives you slightly more checking.
>
> The implementation will probably generate &lt; and &gt; rather than
> CDATA; XML says they're equivalent.
>
> In XQuery 3 there's a per-element serialization option for CDATA
> sections,
>
> http://www.w3.org/TR/xslt-xquery-serialization-30/#XML_CDATA-SECTION-ELEMENTS
> so if BaseX implements that you have a way to get closer to what you
> want, perhaps, e.g. for generating RSS. However, you'd still need to
> construct a string containing "<h1>" etc.
>
> Liam
>
>
> --
> Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
> Pictures from old books: http://fromoldbooks.org/
> Ankh: irc.sorcery.net irc.gnome.org freenode/#xml
>
>
_______________________________________________
BaseX-Talk mailing list
BaseX-Talk@mailman.uni-konstanz.de
https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk

Reply via email to