From: <sju...@ko...> - 2004-05-28 20:44:47
|
The following function won't parse one xpath expression in one single case: declare function fn:display($hits as node()+) as element() { let $current := item-at($hits, 1), $top := $current/topicClass/@top, $mid := $current/topicClass/@mid, $botm := $current/topicClass/@botm, $count := count($current/entryref) return <entry> { for $p in 1 to $count let $entry := item-at($current/entryref, $p), $lang := $entry/@xml:lang, $common := $entry/entry/common <=== This is the problem return <entryref xml:lang="{$lang}"> {$common} </entryref> } </entry> }; The problem is that $common returns _nothing_ as long as I use anything more than the simple variable $entry on the right hand side of the asignment. That is: $common := $entry returns the expected sequence, whereas $common := $entry/entry $common := $entry/entry/common $common := $entry/@xml:lang does not return _anything_, even though the same xpath expression does return the expected result for other variables (e.g. $lang). I believe I have tried everything, even renaming the variable, but to no avail. The input data has the following structure in the database: <entry id="5727"> <topicClass top="F" mid="F0000" botm="FN0010"/> <entryref xml:lang="sme"> <xi:include href="terms-sme.xml#xpointer(//entry[@id='deatta#S'])" /> </entryref> <entryref xml:lang="nor"> <xi:include href="terms-nor.xml#xpointer(//entry[@id='trykk#S'])" /> </entryref> </entry> which after XInclude expansion becomes: <entry> <entryref xml:lang="sme"> <entry id="deatta#S"> <common> <head pos="S">deatta</head> ... </common> <senses> ... </senses> </entry> </entryref> <entryref xml:lang="nor"> ... (same as above) </entryref> </entry> Looking at the log file, there is an xinclude processing difference relating to the different $common asignments. $common := $entry gives log entries: 28 May 2004 23:25:14,914 [Thread-14] DEBUG (XQueryPool.java [borrowCompiledXQuery]:80) - file:/Library/Tomcat/ webapps/exist/sami/termrequest.xq is invalid 28 May 2004 23:25:14,965 [Thread-14] DEBUG (XQuery.java [compile]:93) - compilation took 47 28 May 2004 23:25:14,970 [Thread-14] DEBUG (EvalFunction.java [eval]:99) - eval: for $r in document('/db/ordba se/terms/SD-terms/termcenter.xml')//entry[@id &= '5727'] return $r 28 May 2004 23:25:15,136 [Thread-14] DEBUG (EvalFunction.java [eval]:121) - found 1 for for $r in document('/d b/ordbase/terms/SD-terms/termcenter.xml')//entry[@id &= '5727'] return $r 28 May 2004 23:25:15,558 [Thread-14] DEBUG (LocalXPathQueryService.java [execute]:213) - query took 645 ms. 28 May 2004 23:25:15,564 [Thread-14] DEBUG (XIncludeFilter.java [startElement]:141) - processing include ... 28 May 2004 23:25:15,567 [Thread-14] DEBUG (XIncludeFilter.java [processXInclude]:159) - found href="terms-sme .xml#xpointer(//entry[@id='deatta#S'])" 28 May 2004 23:25:15,570 [Thread-14] DEBUG (XIncludeFilter.java [processXInclude]:167) - found xpointer: xpoin ter(//entry[@id='deatta#S']) 28 May 2004 23:25:15,582 [Thread-14] DEBUG (XIncludeFilter.java [processXInclude]:175) - loading /db/ordbase/t erms/SD-terms/terms-sme.xml 28 May 2004 23:25:15,587 [Thread-14] INFO (XIncludeFilter.java [processXInclude]:229) - xpointer query: (ROOT /descendant-or-self::entry[(attribute::id = deatta#S)]) 28 May 2004 23:25:16,040 [Thread-14] INFO (XIncludeFilter.java [processXInclude]:235) - xpointer found: 1 28 May 2004 23:25:16,048 [Thread-14] DEBUG (XIncludeFilter.java [startElement]:141) - processing include ... 28 May 2004 23:25:16,051 [Thread-14] DEBUG (XIncludeFilter.java [processXInclude]:159) - found href="terms-nor .xml#xpointer(//entry[@id='trykk#S'])" 28 May 2004 23:25:16,054 [Thread-14] DEBUG (XIncludeFilter.java [processXInclude]:167) - found xpointer: xpoin ter(//entry[@id='trykk#S']) 28 May 2004 23:25:16,057 [Thread-14] DEBUG (XIncludeFilter.java [processXInclude]:175) - loading /db/ordbase/t erms/SD-terms/terms-nor.xml 28 May 2004 23:25:16,065 [Thread-14] INFO (XIncludeFilter.java [processXInclude]:229) - xpointer query: (ROOT /descendant-or-self::entry[(attribute::id = trykk#S)]) 28 May 2004 23:25:16,430 [Thread-14] INFO (XIncludeFilter.java [processXInclude]:235) - xpointer found: 1 whereas $common := $entry/entry/common gives log entries: 28 May 2004 23:20:38,863 [Thread-15] DEBUG (XQueryPool.java [borrowCompiledXQuery]:80) - file:/Library/Tomcat/ webapps/exist/sami/termrequest.xq is invalid 28 May 2004 23:20:39,072 [Thread-15] DEBUG (XQuery.java [compile]:93) - compilation took 206 28 May 2004 23:20:39,076 [Thread-15] DEBUG (EvalFunction.java [eval]:99) - eval: for $r in document('/db/ordba se/terms/SD-terms/termcenter.xml')//entry[@id &= '5727'] return $r 28 May 2004 23:20:39,370 [Thread-15] DEBUG (EvalFunction.java [eval]:121) - found 1 for for $r in document('/d b/ordbase/terms/SD-terms/termcenter.xml')//entry[@id &= '5727'] return $r 28 May 2004 23:20:39,918 [Thread-15] DEBUG (LocalXPathQueryService.java [execute]:213) - query took 1056 ms. (I don't know the cause of the log entry about the xq file being invalid, but since it's there in both cases, that could not be the reason, whatever it is) It seems that the XInclude statements are not processed at all in the latter case, although the statements themselves are removed. To me it seems like eXist is shortcutting too much when evaluating/compiling the xquery, such that the XInclude expansion happens *after* the $common assignment. If so, the assignment will not succeed, which would explain this behaviour. The function is a modified version of the xquery/biblio.xq example in the distribution, and the above function is used to "postprocess"/restructure the result set (or so I believed) before display, which made me assume that the function would have access to the whole XInclude-expanded structure. This looks like an eXist bug to me. Or is there anything I have missed? I am using the latest snapshot of today. Regards, Sjur |