@@ -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 >
0 commit comments