xquery version "%(xquery_version)s";
declare namespace lom="http://ltsc.ieee.org/xsd/LOM";
declare namespace lomfrens="http://pratic.ens-lyon.fr/xsd/LOMFRENS";
declare namespace xsl="http://www.w3.org/1999/XSL/Transform";
declare namespace util="http://exist-db.org/xquery/util";

let $res := doc("%(url_meta)s")/lom:lom,
    $url   := normalize-space($res/%(resource_url)s),
    $url_img := normalize-space($res//lomfrens:ensDocumentLabel/text()),
    $date_aff:= $res/lom:lifeCycle/lom:contribute[lom:role/lom:value='publisher']/lom:date/lom:dateTime/text(),
    $description := normalize-space(replace($res/lom:general/lom:description/lom:string/text(), '&#xA;', ' ')),
    $rscType := string-join(distinct-values($res/lomfrens:ensData/lomfrens:ensDocumentType/lomfrens:value/text()), ", "),
    $titre := normalize-space($res/lom:general/lom:title/lom:string/text())

return
  <res>
  <title>{$titre}</title>
  <description>{$description}</description>
        <a href="{$url}" title="{$description}">
            <img src="{$url_img}" alt="{$url_img}" width="200"/>
            <p class="portletImageTitle">{$titre}</p>
        </a>
  <pubdate>{$date_aff}</pubdate>
  <type>{$rscType}</type>
</res>

         
 