Problem with menu found and fixed
Posted by mholmes on 11 Jan 2008 in Activity log
I noticed that the menu was incomplete on the IALLT Journal site. A little poking around revealed that it was an XQuery problem related to testing the equality of strings. If I do this:
declare function f:buildMainMenuItems() as element()*
{
let $site := collection('/db/teiJournal/site')//TEI[@xml:id='sitePages']/text/body
for $div in $site/div
return (
if ($div/@rend = 'link_only') then
<li><a href="{$div/head/ref/@target}">{data($div/head/@n)}</a></li>
else
if ($div/@rend != 'page_only') then
<li><a href="site.xhtml?id={$div/@xml:id}">{data($div/head/@n)}</a></li>
else
()
)
};
then the "not equals" test will fail for some reason; it even fails if I use compare(). However, if I turn the test around:
declare function f:buildMainMenuItems() as element()*
{
let $site := collection('/db/teiJournal/site')//TEI[@xml:id='sitePages']/text/body
for $div in $site/div
return (
if ($div/@rend = 'link_only') then
<li><a href="{$div/head/ref/@target}">{data($div/head/@n)}</a></li>
else
if ($div/@rend = 'page_only') then
()
else
<li><a href="site.xhtml?id={$div/@xml:id}">{data($div/head/@n)}</a></li>
)
};
then it works. I'm not sure why; perhaps it's something odd in the way eXist handles string comparisons, or perhaps it's because I'm comparing a node instead of its text, but in that case I don't see why the equals should work either. In any case, it's a live site, so I had to do a quick fix to get it working. If this shows up on any other site, it'll be worth figuring out the problem.