@@ -380,7 +380,7 @@ WHERE
380380 <xsl : variable name =" object-uris" select =" distinct-values($resource/*/@rdf:resource[not(key('resources', .))])" as =" xs:string*" />
381381 <xsl : variable name =" query-string" select =" $object-metadata-query || ' VALUES $this { ' || string-join(for $uri in $object-uris return '< ' || $uri || '> ', ' ') || ' }'" as =" xs:string" />
382382 <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 =" document($request-uri)" as =" document-node()" />
383+ <xsl : variable name =" object-metadata" select =" if (doc-available($request-uri)) then document($request-uri) else () " as =" document-node()? " />
384384 <xsl : message >
385385 $object-uris: <xsl : value-of select =" $object-uris" />
386386 $object-metadata: <xsl : value-of select =" serialize($object-metadata)" />
@@ -587,7 +587,6 @@ WHERE
587587 <xsl : variable name =" id" select =" ixsl:get($form, 'id')" as =" xs:string" />
588588 <xsl : variable name =" action" select =" ixsl:get($form, 'action')" as =" xs:anyURI" />
589589 <xsl : variable name =" enctype" select =" ixsl:get($form, 'enctype')" as =" xs:string" />
590- <!-- <xsl:variable name="accept" select="'application/xhtml+xml'" as="xs:string"/>-->
591590 <xsl : variable name =" about" select =" $block/@about" as =" xs:anyURI" />
592591 <xsl : message >ldh:base-uri(.): <xsl : value-of select =" ldh:base-uri(.)" /></xsl : message >
593592 <xsl : variable name =" etag" select =" ixsl:get(ixsl:get(ixsl:get(ixsl:window(), 'LinkedDataHub.contents'), '`' || ac:absolute-path(ldh:base-uri(.)) || '`'), 'etag')" as =" xs:string" />
@@ -770,56 +769,60 @@ WHERE
770769 </xsl : when >
771770 <!-- POST or PUT constraint violation response is 422 Unprocessable Entity, bad RDF syntax is 400 Bad Request -->
772771 <xsl : when test =" ?status = (400, 422) and starts-with(?media-type, 'application/rdf+xml')" > <!-- allow 'application/rdf+xml;charset=UTF-8' as well -->
772+ <xsl : variable name =" forClass" select =" $container/@typeof" as =" xs:anyURI" />
773+ <xsl : variable name =" resource" select =" key('resources-by-type', $forClass, ?body)[not(key('predicates-by-object', @rdf:nodeID)[not(../rdf:type/@rdf:resource = '&spin; ConstraintViolation')])]" as =" element()" />
774+ <!-- TO-DO: refactor to use asynchronous HTTP requests -->
775+ <xsl : variable name =" types" select =" distinct-values($resource/rdf:type/@rdf:resource)" as =" xs:anyURI*" />
776+ <xsl : variable name =" property-uris" select =" distinct-values($resource/*/concat(namespace-uri(), local-name()))" as =" xs:string*" />
777+ <xsl : variable name =" query-string" select =" 'DESCRIBE $Type VALUES $Type { ' || string-join(for $uri in $property-uris return '< ' || $uri || '> ', ' ') || ' }'" as =" xs:string" />
778+ <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" />
779+ <xsl : variable name =" property-metadata" select =" document($request-uri)" as =" document-node()" />
780+
781+ <xsl : variable name =" query-string" select =" $constructor-query || ' VALUES $Type { ' || string-join(for $type in $types return '< ' || $type || '> ', ' ') || ' }'" as =" xs:string" />
782+ <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" />
783+ <xsl : variable name =" constructors" select =" if (exists($types)) then document($request-uri) else ()" as =" document-node()?" />
784+
785+ <xsl : message >
786+ ConstraintViolation $constructors: <xsl : value-of select =" serialize($constructors)" />
787+ </xsl : message >
788+
789+ <xsl : variable name =" query-string" select =" $constraint-query || ' VALUES $Type { ' || string-join(for $type in $types return '< ' || $type || '> ', ' ') || ' }'" as =" xs:string" />
790+ <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" />
791+ <xsl : variable name =" constraints" select =" if (exists($types)) then document($request-uri) else ()" as =" document-node()?" />
773792
774- <xsl : variable name =" body" select =" ?body" as =" document-node()" />
775- <!-- iterate each form fieldset as resource -->
776- <xsl : for-each select =" $form/fieldset" >
777- <!-- guard against multiple subject URI/bnode values as there can be nested fieldsets -->
778- <xsl : variable name =" resource-uri" select =" (.//input[@name = 'su'])[1]/ixsl:get(., 'value')" as =" xs:anyURI?" />
779- <xsl : variable name =" resource-bnode" select =" (.//input[@name = 'sb'])[1]/ixsl:get(., 'value')" as =" xs:string?" />
780- <xsl : message >
781- $resource-uri: <xsl : value-of select =" $resource-uri" />
782- $resource-bnode: <xsl : value-of select =" $resource-bnode" />
783- </xsl : message >
784- <!-- select violations specific to this resource -->
785- <!-- TO-DO: key('violations-by-value', $resources//*/@rdf:resource, ?body) -->
786- <xsl : variable name =" violations" select =" key('violations-by-root', ($resource-uri, $resource-bnode), $body) | key('violations-by-focus-node', ($resource-uri, $resource-bnode), $body)" as =" element()*" />
787- <xsl : message >$violations: <xsl : value-of select =" serialize($violations)" /></xsl : message >
788-
789- <!-- iterate control groups as properties -->
790- <xsl : for-each select =" ./div[contains-token(@class, 'control-group')][input[@name = 'pu']]" >
791- <xsl : variable name =" predicate" select =" input[@name = 'pu']/ixsl:get(., 'value')" as =" xs:anyURI" />
792-
793- <xsl : choose >
794- <!-- if there are SPIN or SHACL violations specific to the predicate of this control group, set error class on the group -->
795- <!-- TO-DO: @rdf:resource = $violations/ldh:violationValue -->
796- <xsl : when test =" $violations[spin:violationPath/@rdf:resource = $predicate or sh:resultPath/@rdf:resource = $predicate]" >
797- <xsl : sequence select =" ixsl:call(ixsl:get(., 'classList'), 'toggle', [ 'error', true() ])[current-date() lt xs:date('2000-01-01')]" />
798- </xsl : when >
799- <!-- otherwise, remove the error class -->
800- <xsl : otherwise >
801- <xsl : sequence select =" ixsl:call(ixsl:get(., 'classList'), 'toggle', [ 'error', false() ])[current-date() lt xs:date('2000-01-01')]" />
802- </xsl : otherwise >
803- </xsl : choose >
804- </xsl : for-each >
805-
806- <xsl : for-each select =" ./div[contains-token(@class, 'violations')]" >
807- <xsl : choose >
808- <!-- render violations if they exist for this resource -->
809- <xsl : when test =" exists($violations)" >
810- <xsl : result-document href =" ?." method =" ixsl:replace-content" >
811- <xsl : apply-templates select =" $violations" mode =" bs2:Violation" />
812- </xsl : result-document >
813- <ixsl : set-style name =" display" select =" 'block'" />
814- </xsl : when >
815- <!-- hide any previous violations if this resource now has none -->
816- <xsl : otherwise >
817- <ixsl : set-style name =" display" select =" 'none'" />
818- </xsl : otherwise >
819- </xsl : choose >
820- </xsl : for-each >
821- </xsl : for-each >
793+ <xsl : variable name =" query-string" select =" $shape-query || ' VALUES $Type { ' || string-join(for $type in $types return '< ' || $type || '> ', ' ') || ' }'" as =" xs:string" />
794+ <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" />
795+ <xsl : variable name =" shapes" select =" document($request-uri)" as =" document-node()" />
796+
797+ <xsl : variable name =" object-uris" select =" distinct-values($resource/*/@rdf:resource[not(key('resources', .))])" as =" xs:string*" />
798+ <xsl : variable name =" query-string" select =" $object-metadata-query || ' VALUES $this { ' || string-join(for $uri in $object-uris return '< ' || $uri || '> ', ' ') || ' }'" as =" xs:string" />
799+ <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" />
800+ <xsl : variable name =" object-metadata" select =" if (doc-available($request-uri)) then document($request-uri) else ()" as =" document-node()?" />
801+ <xsl : message >
802+ $object-uris: <xsl : value-of select =" $object-uris" />
803+ $object-metadata: <xsl : value-of select =" serialize($object-metadata)" />
804+ </xsl : message >
805+
806+ <xsl : variable name =" row-form" as =" node()*" >
807+ <xsl : apply-templates select =" $resource" mode =" bs2:RowForm" >
808+ <xsl : with-param name =" method" select =" $form/@method" />
809+ <!-- <xsl:with-param name="type-metadata" select="$type-metadata" tunnel="yes"/>-->
810+ <xsl : with-param name =" property-metadata" select =" $property-metadata" tunnel =" yes" />
811+ <xsl : with-param name =" constructors" select =" $constructors" tunnel =" yes" />
812+ <xsl : with-param name =" constraints" select =" $constraints" tunnel =" yes" />
813+ <xsl : with-param name =" shapes" select =" $shapes" tunnel =" yes" />
814+ <xsl : with-param name =" object-metadata" select =" $object-metadata" tunnel =" yes" />
815+ </xsl : apply-templates >
816+ </xsl : variable >
822817
818+ <xsl : for-each select =" $block" >
819+ <xsl : result-document href =" ?." method =" ixsl:replace-content" >
820+ <xsl : copy-of select =" $row-form/*" />
821+ </xsl : result-document >
822+
823+ <xsl : apply-templates select =" ." mode =" ldh:PostConstruct" />
824+ </xsl : for-each >
825+
823826 <ixsl : set-style name =" cursor" select =" 'default'" object =" ixsl:page()//body" />
824827 </xsl : when >
825828 <!-- error response -->
0 commit comments