Skip to content

Commit 7b46216

Browse files
committed
separate package for evaluating resource parameter
1 parent 14f2738 commit 7b46216

File tree

6 files changed

+92
-44
lines changed

6 files changed

+92
-44
lines changed

saxon-local.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ http://www.saxonica.com/documentation/index/configuration-file.html
1818
sourceLocation="xsl/tree.xsl"/>
1919
<package name="https://scdh.github.io/dts-transformations/xsl/tree-hook.xsl" version="1.0.0"
2020
sourceLocation="xsl/tree-hook.xsl"/>
21+
<package name="https://scdh.github.io/dts-transformations/xsl/resource.xsl" version="1.0.0"
22+
sourceLocation="xsl/resource.xsl"/>
2123
<package name="https://scdh.github.io/dts-transformations/xsl/navigation.xsl"
2224
version="1.0.0" sourceLocation="xsl/navigation.xsl"/>
2325
<package name="https://scdh.github.io/dts-transformations/xsl/document.xsl" version="1.0.0"

test/saxon.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ This configuration
2525
sourceLocation="../xsl/tree.xsl"/>
2626
<package name="https://scdh.github.io/dts-transformations/xsl/tree-hook.xsl" version="1.0.0"
2727
sourceLocation="../xsl/tree-hook.xsl"/>
28+
<package name="https://scdh.github.io/dts-transformations/xsl/resource.xsl" version="1.0.0"
29+
sourceLocation="../xsl/resource.xsl"/>
2830

2931
<package name="https://scdh.github.io/dts-transformations/xsl/uri-templates/base.xsl"
3032
version="1.0.0" sourceLocation="../xsl/uri-templates/base.xsl"/>

xsl/document.xsl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ no matter what the $mediaType parameter is set to.
5353

5454
<xsl:mode name="document" on-no-match="fail" visibility="public"/>
5555

56+
<xsl:use-package name="https://scdh.github.io/dts-transformations/xsl/resource.xsl"
57+
package-version="1.0.0">
58+
<xsl:accept component="function" names="dts:resource-uri#0" visibility="public"/>
59+
<xsl:accept component="*" names="*" visibility="hidden"/>
60+
</xsl:use-package>
61+
5662
<xsl:use-package name="https://scdh.github.io/dts-transformations/xsl/tree-hook.xsl"
5763
package-version="1.0.0"/>
5864

@@ -72,7 +78,7 @@ no matter what the $mediaType parameter is set to.
7278
<xsl:assert test="$resource" error-code="{$dts:http400 => dts:error-to-eqname()}">
7379
<xsl:value-of xml:space="preserve">ERROR: resource parameter missing</xsl:value-of>
7480
</xsl:assert>
75-
<xsl:apply-templates mode="document" select="doc($resource)"/>
81+
<xsl:apply-templates mode="document" select="dts:resource-uri() => doc()"/>
7682
</xsl:template>
7783

7884
<xsl:template mode="document" match="document-node(element(TEI))" use-when="$media-type-package">

xsl/navigation.xsl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ See the section at the end of the package.
6868
<xsl:use-package name="https://scdh.github.io/dts-transformations/xsl/dts.xsl"
6969
package-version="1.0.0"/>
7070

71+
<xsl:use-package name="https://scdh.github.io/dts-transformations/xsl/resource.xsl"
72+
package-version="1.0.0">
73+
<xsl:accept component="function" names="dts:resource-uri#0" visibility="public"/>
74+
<xsl:accept component="*" names="*" visibility="hidden"/>
75+
</xsl:use-package>
76+
7177
<xsl:use-package _name="{$uri-templates-package}"
7278
_package-version="{$uri-templates-package-version}">
7379
<!-- an URI templates package must provide two functions -->
@@ -86,7 +92,7 @@ See the section at the end of the package.
8692
<xsl:assert test="$resource" error-code="{$dts:http400 => dts:error-to-eqname()}">
8793
<xsl:value-of xml:space="preserve">ERROR: resource parameter missing</xsl:value-of>
8894
</xsl:assert>
89-
<xsl:apply-templates mode="navigation" select="doc($resource)"/>
95+
<xsl:apply-templates mode="navigation" select="dts:resource-uri() => doc()"/>
9096
</xsl:template>
9197

9298
<!-- the navigation mode is the entry point with a global context node -->

xsl/resource.xsl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<xsl:package name="https://scdh.github.io/dts-transformations/xsl/resource.xsl"
2+
package-version="1.0.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3+
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:map="http://www.w3.org/2005/xpath-functions/map"
4+
xmlns:dts="https://distributed-text-services.github.io/specifications/"
5+
exclude-result-prefixes="#all" xpath-default-namespace="http://www.tei-c.org/ns/1.0" version="3.0">
6+
7+
<xsl:param name="resource" as="xs:string?" select="()"/>
8+
9+
<!-- turn this to false() to make processing DTS endpoint conformant -->
10+
<xsl:param name="absent-resource-from-baseuri" as="xs:boolean" static="true" select="true()"/>
11+
12+
<xsl:use-package name="https://scdh.github.io/dts-transformations/xsl/errors.xsl"
13+
package-version="1.0.0"/>
14+
15+
<!-- used as part of the parameter validation -->
16+
<xsl:function name="dts:validate-resource-parameter" as="map(xs:string, item())"
17+
visibility="public">
18+
<xsl:param name="context" as="node()"/>
19+
<xsl:map>
20+
<xsl:choose>
21+
<xsl:when test="not(empty($resource))">
22+
<xsl:map-entry key="'resource'" select="$resource"/>
23+
</xsl:when>
24+
<xsl:when test="$absent-resource-from-baseuri">
25+
<xsl:map-entry key="'resource'" select="base-uri($context)"/>
26+
</xsl:when>
27+
<xsl:otherwise>
28+
<xsl:message terminate="yes" error-code="{$dts:http400 => dts:error-to-eqname()}">
29+
<xsl:value-of xml:space="preserve">ERROR: resource parameter missing</xsl:value-of>
30+
</xsl:message>
31+
</xsl:otherwise>
32+
</xsl:choose>
33+
</xsl:map>
34+
</xsl:function>
35+
36+
<!-- Maps the resource parameter to a URI. This implementation is identity. -->
37+
<xsl:function name="dts:resource-uri" as="xs:string?" visibility="public">
38+
<xsl:sequence select="$resource"/>
39+
</xsl:function>
40+
41+
</xsl:package>

xsl/tree.xsl

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
xmlns:dts="https://distributed-text-services.github.io/specifications/"
88
exclude-result-prefixes="#all" xpath-default-namespace="http://www.tei-c.org/ns/1.0" version="3.0">
99

10-
<xsl:param name="resource" as="xs:string?" select="()"/>
11-
1210
<xsl:param name="ref" as="xs:string?" select="()"/>
1311

1412
<xsl:param name="start" as="xs:string?" select="()"/>
@@ -22,8 +20,11 @@
2220
contained in the constructed subtree of the parent member. -->
2321
<xsl:param name="marked-virtual-children" as="xs:boolean" select="false()"/>
2422

25-
<!-- turn this to false() to make processing DTS endpoint conformant -->
26-
<xsl:param name="absent-resource-from-baseuri" as="xs:boolean" static="true" select="true()"/>
23+
<xsl:use-package name="https://scdh.github.io/dts-transformations/xsl/resource.xsl"
24+
package-version="1.0.0">
25+
<xsl:accept component="variable" names="resource" visibility="public"/>
26+
<xsl:accept component="function" names="dts:validate-resource-parameter#1" visibility="public"/>
27+
</xsl:use-package>
2728

2829
<xsl:use-package name="https://scdh.github.io/dts-transformations/xsl/errors.xsl"
2930
package-version="1.0.0"/>
@@ -33,44 +34,34 @@
3334

3435
<xsl:function name="dts:validate-parameters" as="map(xs:string, item())" visibility="final">
3536
<xsl:param name="context" as="node()"/>
36-
<xsl:map>
37-
<xsl:choose>
38-
<xsl:when test="not(empty($resource))">
39-
<xsl:map-entry key="'resource'" select="$resource"/>
40-
</xsl:when>
41-
<xsl:when test="$absent-resource-from-baseuri">
42-
<xsl:map-entry key="'resource'" select="base-uri($context)"/>
43-
</xsl:when>
44-
<xsl:otherwise>
45-
<xsl:message terminate="yes" error-code="{$dts:http400 => dts:error-to-eqname()}">
46-
<xsl:value-of xml:space="preserve">ERROR: resource parameter missing</xsl:value-of>
47-
</xsl:message>
48-
</xsl:otherwise>
49-
</xsl:choose>
50-
<xsl:choose>
51-
<xsl:when test="$ref and ($start or $end)">
52-
<xsl:message terminate="yes" error-code="{$dts:http400 => dts:error-to-eqname()}">
53-
<xsl:value-of xml:space="preserve">ERROR: bad parameter combination: when ref is used, start and end must not</xsl:value-of>
54-
</xsl:message>
55-
</xsl:when>
56-
<xsl:when test="$ref">
57-
<xsl:map-entry key="'ref'" select="$ref"/>
58-
</xsl:when>
59-
<xsl:when test="$start and $end">
60-
<xsl:map-entry key="'start'" select="$start"/>
61-
<xsl:map-entry key="'end'" select="$end"/>
62-
</xsl:when>
63-
<xsl:when test="not($start or $end)"/>
64-
<xsl:otherwise>
65-
<xsl:message terminate="yes" error-code="{$dts:http400 => dts:error-to-eqname()}">
66-
<xsl:value-of xml:space="preserve">ERROR: bad parameter combination: start required end and vice versa</xsl:value-of>
67-
</xsl:message>
68-
</xsl:otherwise>
69-
</xsl:choose>
70-
<xsl:if test="$tree">
71-
<xsl:map-entry key="'tree'" select="$tree"/>
72-
</xsl:if>
73-
</xsl:map>
37+
<xsl:variable name="parms" as="map(xs:string, item())">
38+
<xsl:map>
39+
<xsl:choose>
40+
<xsl:when test="$ref and ($start or $end)">
41+
<xsl:message terminate="yes" error-code="{$dts:http400 => dts:error-to-eqname()}">
42+
<xsl:value-of xml:space="preserve">ERROR: bad parameter combination: when ref is used, start and end must not</xsl:value-of>
43+
</xsl:message>
44+
</xsl:when>
45+
<xsl:when test="$ref">
46+
<xsl:map-entry key="'ref'" select="$ref"/>
47+
</xsl:when>
48+
<xsl:when test="$start and $end">
49+
<xsl:map-entry key="'start'" select="$start"/>
50+
<xsl:map-entry key="'end'" select="$end"/>
51+
</xsl:when>
52+
<xsl:when test="not($start or $end)"/>
53+
<xsl:otherwise>
54+
<xsl:message terminate="yes" error-code="{$dts:http400 => dts:error-to-eqname()}">
55+
<xsl:value-of xml:space="preserve">ERROR: bad parameter combination: start required end and vice versa</xsl:value-of>
56+
</xsl:message>
57+
</xsl:otherwise>
58+
</xsl:choose>
59+
<xsl:if test="$tree">
60+
<xsl:map-entry key="'tree'" select="$tree"/>
61+
</xsl:if>
62+
</xsl:map>
63+
</xsl:variable>
64+
<xsl:sequence select="map:merge(($parms, dts:validate-resource-parameter($context)))"/>
7465
</xsl:function>
7566

7667

0 commit comments

Comments
 (0)