Skip to content

Commit 2ca42d8

Browse files
committed
ldh:parent-origin function
1 parent 158db54 commit 2ca42d8

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/imports/default.xsl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,32 @@ exclude-result-prefixes="#all"
7474
<xsl:sequence select="$acl:mode"/>
7575
</xsl:function>
7676

77+
78+
<!-- Strips the leftmost subdomain and returns parent dataspace origin (scheme + host + port) -->
79+
<xsl:function name="ldh:parent-origin" as="xs:anyURI?">
80+
<xsl:param name="uri" as="xs:anyURI"/>
81+
82+
<xsl:variable name="scheme" select="replace($uri, '^(https?://).*$', '$1')" as="xs:string"/>
83+
<xsl:variable name="host" select="replace($uri, '^https?://([^/:]+).*$', '$1')" as="xs:string"/>
84+
<xsl:variable name="port" select="if (matches($uri, ':\d+')) then replace($uri, '^https?://[^:]+:(\d+).*$', '$1') else ''" as="xs:string"/>
85+
86+
<!-- Split host by dots -->
87+
<xsl:variable name="parts" select="tokenize($host, '\.')" as="xs:string+"/>
88+
89+
<xsl:choose>
90+
<!-- If only one part (e.g., "localhost"), return empty - no parent -->
91+
<xsl:when test="count($parts) = 1">
92+
<xsl:sequence select="()"/>
93+
</xsl:when>
94+
<!-- Strip leftmost subdomain -->
95+
<xsl:otherwise>
96+
<xsl:variable name="parent-host" select="string-join(subsequence($parts, 2), '.')" as="xs:string"/>
97+
<xsl:variable name="parent-origin" select="$scheme || $parent-host || (if ($port != '') then (':' || $port) else '') || '/'" as="xs:string"/>
98+
<xsl:sequence select="xs:anyURI($parent-origin)"/>
99+
</xsl:otherwise>
100+
</xsl:choose>
101+
</xsl:function>
102+
77103
<xsl:function name="ldh:request-uri" as="xs:anyURI" use-when="system-property('xsl:product-name') = 'SAXON'">
78104
<xsl:sequence select="$ldh:requestUri"/>
79105
</xsl:function>

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/layout.xsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ LIMIT 100
533533

534534
<xsl:if test="$ldt:base">
535535
<xsl:if test="not($ldt:base = $ac:contextUri)">
536-
<a class="brand context" href="{resolve-uri('..', $ldt:base)}"/>
536+
<a class="brand context" href="{ldh:parent-origin($ldt:base)}"/>
537537
</xsl:if>
538538
</xsl:if>
539539

0 commit comments

Comments
 (0)