1 | <?xml version="1.0" encoding="UTF-8"?> |
---|
2 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" xmlns:owk="http://owark.org/xslt/" |
---|
3 | exclude-result-prefixes="xs xd owk" version="2.0"> |
---|
4 | <xd:doc scope="stylesheet"> |
---|
5 | <xd:desc> |
---|
6 | <xd:p><xd:b>Created on:</xd:b> May 4, 2012</xd:p> |
---|
7 | <xd:p><xd:b>Author:</xd:b> vdv</xd:p> |
---|
8 | <xd:p>Common functions and template for URL rewriting</xd:p> |
---|
9 | </xd:desc> |
---|
10 | </xd:doc> |
---|
11 | <xsl:function name="owk:is-relative" as="xs:boolean"> |
---|
12 | <xsl:param name="url" as="xs:string"/> |
---|
13 | <xsl:sequence select="not(substring-before($url, ':') = ('http', 'https'))"/> |
---|
14 | </xsl:function> |
---|
15 | <xsl:function name="owk:safer-resolve-uri" as="xs:string"> |
---|
16 | <xsl:param name="relative" as="xs:string"/> |
---|
17 | <xsl:param name="hbase" as="xs:string"/> |
---|
18 | <xsl:sequence select="if (owk:is-relative($relative)) then resolve-uri($relative, $hbase) else $relative"/> |
---|
19 | </xsl:function> |
---|
20 | <xsl:function name="owk:url-rewrite" as="xs:string"> |
---|
21 | <xsl:param name="url" as="xs:string"/> |
---|
22 | <xsl:variable name="no-fragment" select="substring-before(concat($url, '#'), '#')"/> |
---|
23 | <xsl:variable name="abs" select="owk:safer-resolve-uri($no-fragment, $base) cast as xs:string"/> |
---|
24 | <xsl:variable name="local-name" select="$index/resource[(for $u in (uri, same-as) return $u cast as xs:string) = $abs][1]/local-name"/> |
---|
25 | <xsl:message>local-name: <xsl:value-of select="$local-name"/></xsl:message> |
---|
26 | <xsl:sequence select="if ($local-name) then concat(if ($resource/uri/@seed = 'false') then '../' else '', $local-name) else owk:safer-resolve-uri($url, $base)"/> |
---|
27 | </xsl:function> |
---|
28 | |
---|
29 | <xsl:variable name="index" select="doc('input:index')/*"/> |
---|
30 | <xsl:variable name="resource" select="doc('input:index-entry')/resource"/> |
---|
31 | <xsl:variable name="base" select="$resource/uri"/> |
---|
32 | </xsl:stylesheet> |
---|