@@ -291,130 +291,135 @@ WHERE
291291
292292 <!-- if the URI is external, dereference it through the proxy -->
293293 <xsl : variable name =" request-uri" select =" ldh:href($ldt:base, ac:absolute-path(ldh:base-uri(.)), map{}, ac:absolute-path(ldh:base-uri(.)), $graph, ())" as =" xs:anyURI" />
294- <xsl : variable name =" request" as =" item()* " >
295- <!-- If-Match header checks preconditions, i.e. that the graph has not been modified in the meanwhile -->
296- < ixsl : schedule-action http-request = " map{ 'method': 'GET', 'href': $request-uri, 'headers': map{ 'Accept': 'application/rdf+xml' } } " >
297- < xsl : call-template name = " ldh:LoadEditedResource " >
298- < xsl : with-param name = " block " select = " $block " />
299- < xsl : with-param name = " about " select = " $about " />
300- </ xsl : call-template >
301- </ ixsl : schedule-action >
302- </ xsl : variable >
303- < xsl : sequence select = " $request[current-date() lt xs:date('2000-01-01')] " />
294+ <xsl : variable name =" http- request" select = " map{ 'method': 'GET', 'href': $request-uri, 'headers': map{ 'Accept': 'application/rdf+xml' } } " as =" map(*) " / >
295+ < xsl : variable name = " callback-context " as = " map(*) " select = "
296+ map{
297+ 'block': $block,
298+ 'about': $about
299+ } " />
300+ < xsl : variable name = " request " select = " map:merge(($http-request, $callback-context)) " as = " map(*) " / >
301+ < xsl : sequence select = " ixsl:http-request($request) = >
302+ ixsl:then(ldh:handle-response($request, ?)) = >
303+ ixsl:then(ldh:load-edited-resource($request, ?)) " />
304304 </xsl : template >
305305
306- <xsl : template name =" ldh:LoadEditedResource" >
307- <xsl : context-item as =" map(*)" use =" required" />
308- <xsl : param name =" block" as =" element()" />
309- <xsl : param name =" about" as =" xs:anyURI" />
310-
311- <xsl : choose >
312- <xsl : when test =" ?status = 200 and ?media-type = 'application/rdf+xml'" >
313- <xsl : variable name =" etag" select =" ?headers?etag" as =" xs:string?" />
314-
315- <xsl : for-each select =" ?body" >
316- <ixsl : set-property name =" {'`' || ac:absolute-path(ldh:base-uri(.)) || '`'}" select =" ldh:new-object()" object =" ixsl:get(ixsl:window(), 'LinkedDataHub.contents')" />
317- <!-- store document under window.LinkedDataHub.contents[$base-uri].results -->
318- <ixsl : set-property name =" results" select =" ." object =" ixsl:get(ixsl:get(ixsl:window(), 'LinkedDataHub.contents'), '`' || ac:absolute-path(ldh:base-uri(.)) || '`')" />
319- <!-- store ETag header value under window.LinkedDataHub.contents[$base-uri].etag -->
320- <ixsl : set-property name =" etag" select =" $etag" object =" ixsl:get(ixsl:get(ixsl:window(), 'LinkedDataHub.contents'), '`' || ac:absolute-path(ldh:base-uri(.)) || '`')" />
321-
322- <xsl : variable name =" resource" select =" key('resources', $about)" as =" element()" /> <!-- TO-DO: handle error -->
323- <xsl : variable name =" types" select =" distinct-values($resource/rdf:type/@rdf:resource)" as =" xs:anyURI*" />
324- <xsl : variable name =" query-string" select =" 'DESCRIBE $Type VALUES $Type { ' || string-join(for $type in $types return '< ' || $type || '> ', ' ') || ' }'" as =" xs:string" />
325- <xsl : variable name =" request-uri" select =" ac:build-uri(resolve-uri('ns', $ldt:base), map{ 'query': $query-string, 'accept': 'application/rdf+xml' })" as =" xs:anyURI" />
306+ <xsl : function name =" ldh:load-edited-resource" as =" item()*" ixsl : updating =" yes" >
307+ <xsl : param name =" request" as =" map(*)" />
308+ <xsl : param name =" response" as =" map(*)" />
309+ <xsl : variable name =" block" select =" $request('block')" as =" element()" />
310+ <xsl : variable name =" about" select =" $request('about')" as =" xs:anyURI" />
326311
327- <xsl : variable name =" request" as =" item()*" >
328- <!-- If-Match header checks preconditions, i.e. that the graph has not been modified in the meanwhile -->
329- <ixsl : schedule-action http-request =" map{ 'method': 'GET', 'href': $request-uri, 'headers': map{ 'Accept': 'application/rdf+xml' } }" >
330- <xsl : call-template name =" ldh:LoadTypeMetadata" >
331- <xsl : with-param name =" block" select =" $block" />
332- <xsl : with-param name =" resource" select =" $resource" />
333- <xsl : with-param name =" types" select =" $types" />
334- </xsl : call-template >
335- </ixsl : schedule-action >
336- </xsl : variable >
337- <xsl : sequence select =" $request[current-date() lt xs:date('2000-01-01')]" />
338- </xsl : for-each >
339- </xsl : when >
340- <!-- error response -->
341- <xsl : otherwise >
342- <ixsl : set-style name =" cursor" select =" 'default'" object =" ixsl:page()//body" />
343- <xsl : sequence select =" ixsl:call(ixsl:window(), 'alert', [ ?message ])" />
344- </xsl : otherwise >
345- </xsl : choose >
346- </xsl : template >
312+ <xsl : for-each select =" $response" >
313+ <xsl : choose >
314+ <xsl : when test =" ?status = 200 and ?media-type = 'application/rdf+xml'" >
315+ <xsl : variable name =" etag" select =" ?headers?etag" as =" xs:string?" />
316+
317+ <xsl : for-each select =" ?body" >
318+ <ixsl : set-property name =" {'`' || ac:absolute-path(ldh:base-uri(.)) || '`'}" select =" ldh:new-object()" object =" ixsl:get(ixsl:window(), 'LinkedDataHub.contents')" />
319+ <!-- store document under window.LinkedDataHub.contents[$base-uri].results -->
320+ <ixsl : set-property name =" results" select =" ." object =" ixsl:get(ixsl:get(ixsl:window(), 'LinkedDataHub.contents'), '`' || ac:absolute-path(ldh:base-uri(.)) || '`')" />
321+ <!-- store ETag header value under window.LinkedDataHub.contents[$base-uri].etag -->
322+ <ixsl : set-property name =" etag" select =" $etag" object =" ixsl:get(ixsl:get(ixsl:window(), 'LinkedDataHub.contents'), '`' || ac:absolute-path(ldh:base-uri(.)) || '`')" />
323+
324+ <xsl : variable name =" resource" select =" key('resources', $about)" as =" element()" /> <!-- TO-DO: handle error -->
325+ <xsl : variable name =" types" select =" distinct-values($resource/rdf:type/@rdf:resource)" as =" xs:anyURI*" />
326+ <xsl : variable name =" query-string" select =" 'DESCRIBE $Type VALUES $Type { ' || string-join(for $type in $types return '< ' || $type || '> ', ' ') || ' }'" as =" xs:string" />
327+ <xsl : variable name =" request-uri" select =" ac:build-uri(resolve-uri('ns', $ldt:base), map{ 'query': $query-string, 'accept': 'application/rdf+xml' })" as =" xs:anyURI" />
328+ <xsl : variable name =" http-request" select =" map{ 'method': 'GET', 'href': $request-uri, 'headers': map{ 'Accept': 'application/rdf+xml' } }" as =" map(*)" />
329+ <xsl : variable name =" callback-context" as =" map(*)" select ="
330+ map{
331+ 'block': $block,
332+ 'resource': $resource,
333+ 'types': $types
334+ }" />
335+ <xsl : variable name =" request" select =" map:merge(($http-request, $callback-context))" as =" map(*)" />
336+ <xsl : sequence select =" ixsl:http-request($request) =>
337+ ixsl:then(ldh:handle-response($request, ?)) =>
338+ ixsl:then(ldh:load-type-metadata($request, ?))" />
339+ </xsl : for-each >
340+ </xsl : when >
341+ <!-- error response -->
342+ <xsl : otherwise >
343+ <ixsl : set-style name =" cursor" select =" 'default'" object =" ixsl:page()//body" />
344+ <xsl : sequence select =" ixsl:call(ixsl:window(), 'alert', [ ?message ])" />
345+ </xsl : otherwise >
346+ </xsl : choose >
347+ </xsl : for-each >
348+ </xsl : function >
347349
348- <xsl : template name =" ldh:LoadTypeMetadata" >
349- <xsl : context-item as =" map(*)" use =" required" />
350- <xsl : param name =" block" as =" element()" />
351- <xsl : param name =" resource" as =" element()" />
352- <xsl : param name =" types" as =" xs:anyURI*" />
350+ <xsl : function name =" ldh:load-type-metadata" as =" item()*" ixsl : updating =" yes" >
351+ <xsl : param name =" request" as =" map(*)" />
352+ <xsl : param name =" response" as =" map(*)" />
353+ <xsl : variable name =" block" select =" $request('block')" as =" element()" />
354+ <xsl : variable name =" resource" select =" $request('resource')" as =" element()" />
355+ <xsl : variable name =" types" select =" $request('types')" as =" xs:anyURI*" />
353356
354- <xsl : choose >
355- <xsl : when test =" ?status = 200 and ?media-type = 'application/rdf+xml'" >
356- <xsl : variable name =" type-metadata" select =" ?body" as =" document-node()?" />
357+ <xsl : for-each select =" $response" >
358+ <xsl : choose >
359+ <xsl : when test =" ?status = 200 and ?media-type = 'application/rdf+xml'" >
360+ <xsl : variable name =" type-metadata" select =" ?body" as =" document-node()?" />
357361
358- <!-- TO-DO: refactor to use asynchronous HTTP requests -->
359- <xsl : variable name =" property-uris" select =" distinct-values($resource/*/concat(namespace-uri(), local-name()))" as =" xs:string*" />
360- <xsl : variable name =" query-string" select =" 'DESCRIBE $Type VALUES $Type { ' || string-join(for $uri in $property-uris return '< ' || $uri || '> ', ' ') || ' }'" as =" xs:string" />
361- <xsl : variable name =" request-uri" select =" ac:build-uri(resolve-uri('ns', $ldt:base), map{ 'query': $query-string, 'accept': 'application/rdf+xml' })" as =" xs:anyURI" />
362- <xsl : variable name =" property-metadata" select =" document($request-uri)" as =" document-node()" />
362+ <!-- TO-DO: refactor to use asynchronous HTTP requests -->
363+ <xsl : variable name =" property-uris" select =" distinct-values($resource/*/concat(namespace-uri(), local-name()))" as =" xs:string*" />
364+ <xsl : variable name =" query-string" select =" 'DESCRIBE $Type VALUES $Type { ' || string-join(for $uri in $property-uris return '< ' || $uri || '> ', ' ') || ' }'" as =" xs:string" />
365+ <xsl : variable name =" request-uri" select =" ac:build-uri(resolve-uri('ns', $ldt:base), map{ 'query': $query-string, 'accept': 'application/rdf+xml' })" as =" xs:anyURI" />
366+ <xsl : variable name =" property-metadata" select =" document($request-uri)" as =" document-node()" />
363367
364- <xsl : variable name =" query-string" select =" $constructor-query || ' VALUES $Type { ' || string-join(for $type in $types return '< ' || $type || '> ', ' ') || ' }'" as =" xs:string" />
365- <xsl : variable name =" request-uri" select =" ac:build-uri(resolve-uri('ns', $ldt:base), map{ 'query': $query-string, 'accept': 'application/sparql-results+xml' })" as =" xs:anyURI" />
366- <xsl : variable name =" constructors" select =" if (exists($types)) then document($request-uri) else ()" as =" document-node()?" />
368+ <xsl : variable name =" query-string" select =" $constructor-query || ' VALUES $Type { ' || string-join(for $type in $types return '< ' || $type || '> ', ' ') || ' }'" as =" xs:string" />
369+ <xsl : variable name =" request-uri" select =" ac:build-uri(resolve-uri('ns', $ldt:base), map{ 'query': $query-string, 'accept': 'application/sparql-results+xml' })" as =" xs:anyURI" />
370+ <xsl : variable name =" constructors" select =" if (exists($types)) then document($request-uri) else ()" as =" document-node()?" />
367371
368- <xsl : variable name =" query-string" select =" $constraint-query || ' VALUES $Type { ' || string-join(for $type in $types return '< ' || $type || '> ', ' ') || ' }'" as =" xs:string" />
369- <xsl : variable name =" request-uri" select =" ac:build-uri(resolve-uri('ns', $ldt:base), map{ 'query': $query-string, 'accept': 'application/sparql-results+xml' })" as =" xs:anyURI" />
370- <xsl : variable name =" constraints" select =" if (exists($types)) then document($request-uri) else ()" as =" document-node()?" />
371-
372- <xsl : variable name =" query-string" select =" $shape-query || ' VALUES $Type { ' || string-join(for $type in $types return '< ' || $type || '> ', ' ') || ' }'" as =" xs:string" />
373- <xsl : variable name =" request-uri" select =" ac:build-uri(resolve-uri('ns', $ldt:base), map{ 'query': $query-string, 'accept': 'application/rdf+xml' })" as =" xs:anyURI" />
374- <xsl : variable name =" shapes" select =" document($request-uri)" as =" document-node()" />
372+ <xsl : variable name =" query-string" select =" $constraint-query || ' VALUES $Type { ' || string-join(for $type in $types return '< ' || $type || '> ', ' ') || ' }'" as =" xs:string" />
373+ <xsl : variable name =" request-uri" select =" ac:build-uri(resolve-uri('ns', $ldt:base), map{ 'query': $query-string, 'accept': 'application/sparql-results+xml' })" as =" xs:anyURI" />
374+ <xsl : variable name =" constraints" select =" if (exists($types)) then document($request-uri) else ()" as =" document-node()?" />
375375
376- <xsl : variable name =" object-uris" select =" distinct-values($resource/*/@rdf:resource[not(key('resources', .))])" as =" xs:string*" />
377- <xsl : variable name =" query-string" select =" $object-metadata-query || ' VALUES $this { ' || string-join(for $uri in $object-uris return '< ' || $uri || '> ', ' ') || ' }'" as =" xs:string" />
378- <xsl : variable name =" request-uri" select =" ac:build-uri(resolve-uri('sparql', $ldt:base), map{ 'query': $query-string, 'accept': 'application/rdf+xml' })" as =" xs:anyURI" />
379- <xsl : variable name =" object-metadata" select =" if (doc-available($request-uri)) then document($request-uri) else ()" as =" document-node()?" />
376+ <xsl : variable name =" query-string" select =" $shape-query || ' VALUES $Type { ' || string-join(for $type in $types return '< ' || $type || '> ', ' ') || ' }'" as =" xs:string" />
377+ <xsl : variable name =" request-uri" select =" ac:build-uri(resolve-uri('ns', $ldt:base), map{ 'query': $query-string, 'accept': 'application/rdf+xml' })" as =" xs:anyURI" />
378+ <xsl : variable name =" shapes" select =" document($request-uri)" as =" document-node()" />
380379
381- <xsl : for-each select =" $block" >
382- <xsl : variable name =" row" as =" node()*" >
383- <xsl : apply-templates select =" $resource" mode =" bs2:RowForm" >
384- <xsl : with-param name =" type-metadata" select =" $type-metadata" tunnel =" yes" />
385- <xsl : with-param name =" property-metadata" select =" $property-metadata" tunnel =" yes" />
386- <xsl : with-param name =" constructors" select =" $constructors" tunnel =" yes" />
387- <xsl : with-param name =" constraints" select =" $constraints" tunnel =" yes" />
388- <xsl : with-param name =" shapes" select =" $shapes" tunnel =" yes" />
389- <xsl : with-param name =" object-metadata" select =" $object-metadata" tunnel =" yes" />
390- </xsl : apply-templates >
391- </xsl : variable >
380+ <xsl : variable name =" object-uris" select =" distinct-values($resource/*/@rdf:resource[not(key('resources', .))])" as =" xs:string*" />
381+ <xsl : variable name =" query-string" select =" $object-metadata-query || ' VALUES $this { ' || string-join(for $uri in $object-uris return '< ' || $uri || '> ', ' ') || ' }'" as =" xs:string" />
382+ <xsl : variable name =" request-uri" select =" ac:build-uri(resolve-uri('sparql', $ldt:base), map{ 'query': $query-string, 'accept': 'application/rdf+xml' })" as =" xs:anyURI" />
383+ <xsl : variable name =" object-metadata" select =" if (doc-available($request-uri)) then document($request-uri) else ()" as =" document-node()?" />
392384
393- <!-- replace block element attributes TO-DO: shouldn't be necessary in SaxonJS 3 using method="ixsl:replace-element": https://saxonica.plan.io/issues/6303#note-2 -->
394- <xsl : for-each select =" @*" >
395- <ixsl : remove-attribute object =" $block" name =" {name()}" />
396- </xsl : for-each >
397- <xsl : for-each select =" $row/@*" >
398- <ixsl : set-attribute object =" $block" name =" {name()}" select =" ." />
385+ <xsl : for-each select =" $block" >
386+ <xsl : variable name =" row" as =" node()*" >
387+ <xsl : apply-templates select =" $resource" mode =" bs2:RowForm" >
388+ <xsl : with-param name =" type-metadata" select =" $type-metadata" tunnel =" yes" />
389+ <xsl : with-param name =" property-metadata" select =" $property-metadata" tunnel =" yes" />
390+ <xsl : with-param name =" constructors" select =" $constructors" tunnel =" yes" />
391+ <xsl : with-param name =" constraints" select =" $constraints" tunnel =" yes" />
392+ <xsl : with-param name =" shapes" select =" $shapes" tunnel =" yes" />
393+ <xsl : with-param name =" object-metadata" select =" $object-metadata" tunnel =" yes" />
394+ </xsl : apply-templates >
395+ </xsl : variable >
396+
397+ <!-- replace block element attributes TO-DO: shouldn't be necessary in SaxonJS 3 using method="ixsl:replace-element": https://saxonica.plan.io/issues/6303#note-2 -->
398+ <xsl : for-each select =" @*" >
399+ <ixsl : remove-attribute object =" $block" name =" {name()}" />
400+ </xsl : for-each >
401+ <xsl : for-each select =" $row/@*" >
402+ <ixsl : set-attribute object =" $block" name =" {name()}" select =" ." />
403+ </xsl : for-each >
404+
405+ <xsl : result-document href =" ?." method =" ixsl:replace-content" >
406+ <xsl : copy-of select =" $row/*" /> <!-- inject the content of div.row-fluid -->
407+ </xsl : result-document >
399408 </xsl : for-each >
400-
401- <xsl : result-document href =" ?." method =" ixsl:replace-content" >
402- <xsl : copy-of select =" $row/*" /> <!-- inject the content of div.row-fluid -->
403- </xsl : result-document >
404- </xsl : for-each >
405409
406- <!-- initialize event listeners -->
407- <xsl : apply-templates select =" $block" mode =" ldh:RenderRowForm" />
410+ <!-- initialize event listeners -->
411+ <xsl : apply-templates select =" $block" mode =" ldh:RenderRowForm" />
408412
409- <ixsl : set-style name =" cursor" select =" 'default'" object =" ixsl:page()//body" />
410- </xsl : when >
411- <!-- error response -->
412- <xsl : otherwise >
413- <ixsl : set-style name =" cursor" select =" 'default'" object =" ixsl:page()//body" />
414- <xsl : sequence select =" ixsl:call(ixsl:window(), 'alert', [ ?message ])" />
415- </xsl : otherwise >
416- </xsl : choose >
417- </xsl : template >
413+ <ixsl : set-style name =" cursor" select =" 'default'" object =" ixsl:page()//body" />
414+ </xsl : when >
415+ <!-- error response -->
416+ <xsl : otherwise >
417+ <ixsl : set-style name =" cursor" select =" 'default'" object =" ixsl:page()//body" />
418+ <xsl : sequence select =" ixsl:call(ixsl:window(), 'alert', [ ?message ])" />
419+ </xsl : otherwise >
420+ </xsl : choose >
421+ </xsl : for-each >
422+ </xsl : function >
418423
419424 <!-- TO-DO: unify -->
420425 <xsl : template match =" div[@typeof]//button[contains-token(@class, 'btn-cancel')][not(contains-token(@class, 'disabled'))]" mode =" ixsl:onclick" >
0 commit comments