سؤال

I'm trying to generate a treeview from a collection (filesystem). Unfortunately some Files have special characters like ü ä and ö. And I'd like to have them html encoded as &­auml;

When I get them from the variable, they are URL encoded. First I decode them to UTF-8 and then .... i don't know how to go further.

<li><a href="#">{util:unescape-uri($child, "UTF-8")}</a>

The function util:parse is doing the exact opposite from that what I want.

Here is the recursive function:

xquery version "3.0";

declare namespace ls="ls";

declare option exist:serialize "method=html media-type=text/html omit-xml-declaration=yes indent=yes";

declare function ls:ls($collection as xs:string, $subPath as xs:string) as element()* {
  if (xmldb:collection-available($collection)) then
    (         
      for $child in xmldb:get-child-collections($collection)
      let $path := concat($collection, '/', $child) 
      let $sPath := concat($subPath, '/', $child)
      order by $child 
      return
        <li><a href="#">{util:unescape-uri($child, "UTF-8")}</a>
          <ul>
          {ls:ls($path,$sPath)}
          </ul>
        </li>,

        for $child in xmldb:get-child-resources($collection)
        let $sPath := concat($subPath, '/', $child)
        order by $child 
        return
            <li> <a href="javascript:loadPage('{$sPath}');">{util:unescape-uri($child, "UTF-8")}</a></li> 
    )
  else ()    
};  

let $collection := request:get-parameter('coll', '/db/apps/ebner-online/resources/xss/xml')
return
  <ul>{ls:ls($collection,"")}</ul> 
هل كانت مفيدة؟

المحلول

Rather than util:unescape-uri(), I would suggest using xmldb:encode-uri() and xmldb:decode-uri(). Use the encode version on a collection or document name when creating/storing it. Use the decode version when displaying the collection or document name. See the function documentation for the xmldb module.

As to forcing &auml; instead of ü, this is an even trickier serialization issue. Both, along with &#228;, are equivalent representations of the same UTF-8 character. Why not just let the character through as ü?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top