Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VERY WIP: TEST CODE
Browse files Browse the repository at this point in the history
dragon-dxw committed Jun 7, 2024
1 parent 3d1f414 commit 641e2e0
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/caselawclient/xquery/get_linked_caselaw.xqy
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ declare namespace akn = "http://docs.oasis-open.org/legaldocml/ns/akn/3.0";
declare namespace uk = "https://caselaw.nationalarchives.gov.uk/akn";
declare variable $uri as xs:string external;

let $_ := if (fn:not(fn:exists($uri))) then (fn:error(xs:QName("FCL-DOCUMENTNOTFOUND"), "No document at "||$uri)) else ()
let $xml := fn:document($uri)
let $external-uris := $xml//akn:ref[@uk:isNeutral=fn:true()]/@href
let $ml-uris := for $uri in $external-uris return fn:concat(fn:replace($uri, ".*/id/", ""), ".xml")
25 changes: 25 additions & 0 deletions src/caselawclient/xquery/xslt_transform.xqy
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
xquery version "1.0-ml";

import module namespace helper = "https://caselaw.nationalarchives.gov.uk/helper" at "/judgments/search/helper.xqy";
declare namespace akn = "http://docs.oasis-open.org/legaldocml/ns/akn/3.0";
declare namespace uk = "https://caselaw.nationalarchives.gov.uk/akn";

declare variable $show_unpublished as xs:boolean? external;
declare variable $uri as xs:string external;
@@ -9,6 +11,28 @@ declare variable $img_location as xs:string? external;
declare variable $xsl_filename as xs:string? external;
declare variable $query as xs:string? external;

declare function local:public-to-marklogic($uri as xs:string) as xs:string
{
(: inspired by https://stackoverflow.com/questions/27745/getting-parts-of-a-url-regex :)
(: https://caselaw.nationalarchives.gov.uk/uksc/2024/1 -> /uksc/2024/1.xml :)
fn:replace($uri, "^.*//[^/]*", "")||".xml"
};

declare function local:marklogic-to-public($uri as xs:string) as xs:string
{
"https://caselaw.nationalarchives.gov.uk/"||fn:replace($uri, ".xml$", "")
};

declare function local:get-linked-caselaw($source-uri as xs:string) (: as returnDatatype:)
{
let $xml := fn:document($source-uri)
let $external-uris := $xml//akn:ref[@uk:isNeutral=fn:true()]/@href
let $ml-uris := for $uri in $external-uris return local:public-to-marklogic($uri)
let $list := for $uri in $ml-uris return <cite href="{$uri}" available="{fn:doc-available($uri)}"/>
(: fn:doc-available(@uri) :)
return <x>{$list}</x>
};

let $judgment_published_property := xdmp:document-get-properties($uri, xs:QName("published"))[1]
let $is_published := $judgment_published_property/text()
let $image_base := if ($img_location) then $img_location else ""
@@ -71,3 +95,4 @@ let $return_value := if($query) then
$retrieved_value

return $return_value
(: return local:get-linked-caselaw($uri) :)

0 comments on commit 641e2e0

Please sign in to comment.