Skip to content

Commit

Permalink
New ldh:href function that takes $graph
Browse files Browse the repository at this point in the history
  • Loading branch information
namedgraph committed Nov 14, 2023
1 parent 9eea790 commit 4663c6c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ exclude-result-prefixes="#all"
</xsl:for-each>

<!-- don't use base-uri() because it's value comes from the last HTML document load -->
<xsl:variable name="request-uri" select="ldh:href($ldt:base, if (starts-with($graph, $ldt:base)) then $graph else ac:absolute-path(xs:anyURI(ixsl:location())), map{}, $content-value)" as="xs:anyURI"/>
<xsl:variable name="request-uri" select="ldh:href($ldt:base, if (starts-with($graph, $ldt:base)) then $graph else ac:absolute-path(xs:anyURI(ixsl:location())), map{}, $content-value, $graph, ())" as="xs:anyURI"/>
<xsl:variable name="request" as="item()*">
<ixsl:schedule-action http-request="map{ 'method': 'GET', 'href': ac:document-uri($request-uri), 'headers': map{ 'Accept': 'application/rdf+xml' } }">
<xsl:call-template name="onContentValueLoad">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ exclude-result-prefixes="#all"
<xsl:param name="absolute-path" as="xs:anyURI"/>
<xsl:param name="query-params" as="map(xs:string, xs:string*)"/>
<xsl:param name="uri" as="xs:anyURI?"/>
<xsl:param name="graph" select="if ($uri) then ac:absolute-path($uri) else ()" as="xs:anyURI?"/>
<xsl:param name="fragment" as="xs:string?"/>

<xsl:choose>
Expand All @@ -109,6 +110,38 @@ exclude-result-prefixes="#all"
</xsl:choose>
</xsl:function>

<xsl:function name="ldh:href" as="xs:anyURI">
<xsl:param name="base" as="xs:anyURI"/>
<xsl:param name="absolute-path" as="xs:anyURI"/>
<xsl:param name="query-params" as="map(xs:string, xs:string*)"/>
<xsl:param name="uri" as="xs:anyURI?"/>
<xsl:param name="graph" as="xs:anyURI?"/>
<xsl:param name="fragment" as="xs:string?"/>

<xsl:choose>
<!-- do not proxy $uri via ?uri= if it is relative to the $base -->
<xsl:when test="$uri and starts-with($uri, $base)">
<xsl:variable name="absolute-path" select="xs:anyURI(if (contains($uri, '#')) then substring-before($uri, '#') else $uri)" as="xs:anyURI"/>
<xsl:variable name="fragment" select="if ($fragment) then $fragment else if (contains($uri, '#')) then substring-after($uri, '#') else ()" as="xs:string?"/>
<xsl:sequence select="xs:anyURI(ac:build-uri($absolute-path, $query-params) || (if ($fragment) then ('#' || $fragment) else ()))"/>
</xsl:when>
<!-- proxy external URI/graph -->
<xsl:when test="$uri and $graph">
<xsl:variable name="fragment" select="if ($fragment) then $fragment else encode-for-uri($uri)" as="xs:string?"/>
<xsl:sequence select="xs:anyURI(ac:build-uri($absolute-path, map:merge((map{ 'uri': string($uri), 'graph': string($graph) }, $query-params))) || (if ($fragment) then ('#' || $fragment) else ()))"/>
</xsl:when>
<!-- proxy external URI -->
<xsl:when test="$uri">
<xsl:variable name="fragment" select="if ($fragment) then $fragment else encode-for-uri($uri)" as="xs:string?"/>
<xsl:sequence select="xs:anyURI(ac:build-uri($absolute-path, map:merge((map{ 'uri': string($uri), 'graph': string($absolute-path) }, $query-params))) || (if ($fragment) then ('#' || $fragment) else ()))"/>
</xsl:when>
<!-- no URI supplied -->
<xsl:otherwise>
<xsl:sequence select="xs:anyURI(ac:build-uri($absolute-path, $query-params) || (if ($fragment) then ('#' || $fragment) else ()))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>

<xsl:function name="ldh:query-params" as="map(xs:string, xs:string*)">
<xsl:param name="mode" as="xs:anyURI*"/>

Expand Down

0 comments on commit 4663c6c

Please sign in to comment.