MJ's progress porting Graves and ACH
Posted by mholmes on 18 Nov 2009 in R & D, Activity log
MDH posting some edited highlights of MJ's work porting the Graves project from eXist 0.9 to 1.4, as a guide to future porting of old projects, and then the subsequent port of the ACH abstracts project. This will be enhanced and updated over time.
- Moved the Graves application code into a Cocoon subfolder called
site
. This is our current preferred method of doing things; it allows us to retain ownership of the files containing the application logic, while the WEB-INF directory can be owned by the user under which Tomcat is running, so it can work with the database. - Moved XQuery files from the project root into an /xq/ subfolder. This is common sense, and is our current practice in all our projects.
- Added the session name space to XQuery files:
declare namespace session="http://exist-db.org/xquery/session";
. - Changed
request:request-parameter
torequest:get-parameter
everywhere. - Changed
util:eval
toutil:eval-with-context
. [Note: I'm not clear on why this was needed, or what the differences are; we should revisit this. I useutil:eval
in many projects. - In addition to the changes from util:eval() to util:eval-with-context(), in some cases I was able to simply remove the erroneous second parameter in the function call:
let $index_query := f:build-index-query("/db/graves/index", $year, $month),
OLD$index := util:eval($index_query, "")
NEW$index := util:eval($index_query)
- Forced some variables to be cast as
xs:int
s, as eXist is more strict about type checking. This was required throughout the original XQuery.
OLD$prev_day := if(($month eq 3) and ($year eq 1935)) then '22' else '01',
NEW$prev_day := if(($month cast as xs:int eq 3) and ($year cast as xs:int eq 1935)) then '22' else '01',
- Updated calls to
request:encode-url
, which now requiresanyURI
type parameters.
OLD:$doc_uri_request := request:encode-url("xrequest.xq")
NEW$doc_uri_request := session:encode-url(request:request-uri())
- Properly escaped ampersands in URL like places.
OLD<prev href="{$doc_uri_request}?action=search&collection=...
NEW<prev href="{$doc_uri_request}?action=search&collection=...
- Updated calls to request:set-session-attribute() to session:set-attribute().
OLDrequest:set-session-attribute("query_stored", "true")
NEWsession:set-attribute("query_stored", "true")
- Changes either to the definition or the functionality of
substring
mean that "bad" code that used to function OK now needs to be fixed; an initial start-position parameter of 0 should have been 1, and although the code used to work (presumably where an invalid value was encountered, eXist substituted 1), now a zero is used, so one fewer characters is returned. Check any start-position params insubstring
to make sure they're 1-based. - Image width and height attributes have been fixed (960 vs 906px).
- Added
@summary
to all tables, with an empty value if it's a layout table. The attribute is required for validation. - Fixed retrieval of multiple instances of reference items when only one was required (and since they have unique ids, the result was invalidity due to duplicate ids)
OLD<xsl:apply-templates select="//rs" mode="annotation" />
NEW<xsl:for-each-group select="//rs" group-by="@key">
<xsl:apply-templates select="." mode="annotation" />
</xsl:for-each-group> - Where older processors expecting an atomic value, when passed a sequence, would use the first element of the sequence, Saxon seems to be more picky. You have to make sure you're passing an atomic value rather than a sequence if that's what the processor expects:
OLD<xsl:sort select="author/name/@reg" />
NEW<xsl:value-of select="author[1]/name[1]/@reg" />
- All
<xsl:element>
and<xsl:attribute>
constructors were replaced by simple inline XHTML code, except where they're necessary. This makes for simplicity and readability. - The Cocoon XInclude transformer appears to be rather unintelligent when it comes to the output of xmlns attributes; it leaves all sorts of unnecessary ones in the output code. MJ came up with a much better solution: a template in the XSLT (2.0) that matches
<xi:include>
, and does this:<xsl:copy-of select="fn:doc('../includes/header.inc')" />
The details are still being worked out; one possible issue is the requirement to know the relative location of the included document during the XSLT process, and another might be when the included document is in the eXist db, not on the file system. - For the ACH, in which the project includes merging a static website (hosted originally on web.uvic.ca) with the Cocoon webapp, there was also a need to change the directory structure slightly, so that all documents are served from URLs in the project root (
cocoon/site
). Previously some were served out of subfolders. This standardization is a good idea generally, and makes it much easier to map the inclusion of images and so on. All my recent projects already work this way.
These are errors relating to the XML of the Graves project itself, not likely to be encountered in other projects:
<div type="Abstract">
should be<div type="abstract">
.- @TEIform attributes are unnecessary and have been deleted; these were, we think, a byproduct of the DTD expansion process that also expanded the entities (which we wanted).
And errors specific to the ACH:
- Missing "http://" at the beginning of a URL in abstract 154.
- Failure of FO for abstract 203 to load (still under investigation).
- Layout issue with the panelist list in abstract 147 (still under investigation).