2013-07-31 31 views
0

我試圖從一個集合(文件系統)中生成一個樹形視圖。不幸的是,一些文件具有特殊字符,如üä和ö。我希望他們的HTML編碼爲&­auml;在eXist-db/XQuery中將字符串編碼爲html

當我從變量中獲得它們時,它們是URL編碼。首先我將它們解碼爲UTF-8,然後....我不知道如何走得更遠。

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

函數util:parse做的和我想要的完全相反。

下面是遞歸函數:

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> 

回答

1

不是util:unescape-uri(),我會建議使用xmldb:encode-uri()xmldb:decode-uri()。創建/存儲集合或文檔名稱時,請使用encode版本。顯示集合或文檔名稱時使用decode版本。見the function documentation for the xmldb module

至於迫使&auml;而不是ü,這是一個更加棘手的問題系列化。兩者和&#228;一樣,都是同一個UTF-8字符的等效表示。爲什麼不讓字符通過ü