Debian Codegraph @

net/sf/saxon/data/override.xsl

raw symbols SCIP
1 <!-- Transformation for handling xs:override in schema processor -->
2 <!-- Copied from Appendix F.2 of the XSD 1.1 Candidate Recommendation dated 21 July 2011 -->
3 <!-- Modified to remove schema-awareness, and to take the source document as principal input -->
4 <!-- Modified to set @xml:base on new xs:override elements -->
5
6 <xsl:transform version="2.0"
7 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
8 xmlns:xs="http://www.w3.org/2001/XMLSchema"
9 xmlns:f="http://www.w3.org/2008/05/XMLSchema-misc"
10 exclude-result-prefixes="f">
11
12 <xsl:param name="overrideElement" as="element(xs:override)"/>
13 <xsl:param name="overriddenSchema" as="element(xs:schema)" select="/*"/>
14 <xsl:param name="xmlBase" as="xs:anyURI" select="base-uri(/)"/>
15
16 <xsl:template match="/">
17 <xsl:apply-templates select="$overriddenSchema"/>
18 </xsl:template>
19
20 <xsl:template match="element(xs:schema)">
21 <xsl:copy>
22 <xsl:copy-of select="@*"/>
23 <!-- MHK addition (bug 17574: add import declarations from the overriding stylesheet if necessary -->
24 <xsl:apply-templates
25 select="$overrideElement/../xs:import[not(@namespace = current()/xs:import/@namespace)]"/>
26 <xsl:apply-templates/>
27 </xsl:copy>
28 </xsl:template>
29
30 <xsl:template match="element(xs:redefine)">
31 <xsl:copy>
32 <xsl:copy-of select="@*"/>
33 <xsl:apply-templates/>
34 </xsl:copy>
35 </xsl:template>
36
37 <xsl:template match="element(xs:import)" priority="5">
38 <xsl:copy>
39 <xsl:copy-of select="@* except @schemaLocation"/>
40 <!-- MHK addition: make schemaLocation absolute -->
41 <xsl:if test="exists(@schemaLocation)">
42 <xsl:attribute name="schemaLocation" select="resolve-uri(@schemaLocation, base-uri(.))"/>
43 </xsl:if>
44 </xsl:copy>
45 </xsl:template>
46
47
48 <!--* replace children of xs:schema, xs:redefine, and xs:override
49 * which match children of $overrideElement. Retain others.
50 *-->
51 <xsl:template match="element(xs:schema)/* | element(xs:redefine)/* | element(xs:override)/*"
52 priority="3">
53 <xsl:variable name="original" select="."/>
54 <xsl:variable name="replacement"
55 select="$overrideElement/*
56 [node-name(.)=node-name($original)
57 and
58 f:componentName(.)=f:componentName($original)]"/>
59 <xsl:copy-of select="($replacement, $original)[1]"/>
60 </xsl:template>
61
62 <!--* replace xs:include elements with overrides
63 *-->
64 <xsl:template match="element(xs:include)" priority="5">
65 <xsl:element name="xs:override">
66 <xsl:attribute name="xml:base" select="(@xml:base, $xmlBase)[1]"/>
67 <xsl:copy-of select="@schemaLocation, $overrideElement/*"/>
68 </xsl:element>
69 </xsl:template>
70
71 <!--* change xs:override elements: children which match
72 * children of $overrideElement are replaced, others are
73 * kept, and at the end all children of $overrideElement
74 * not already inserted are added.
75 *-->
76 <xsl:template match="element(xs:override)"
77 priority="5">
78 <xsl:element name="xs:override">
79 <xsl:attribute name="schemaLocation" select="@schemaLocation"/>
80 <xsl:attribute name="xml:base" select="(@xml:base, $xmlBase)[1]"/>
81 <xsl:apply-templates/>
82 <xsl:apply-templates select="$overrideElement/*" mode="copy-unmatched">
83 <xsl:with-param name="overriddenOverride" select="."/>
84 </xsl:apply-templates>
85 </xsl:element>
86 </xsl:template>
87
88 <xsl:template match="*" mode="copy-unmatched">
89 <xsl:param name="overriddenOverride"></xsl:param>
90 <xsl:variable name="overriding" select="."/>
91 <xsl:variable name="overridden" select="$overriddenOverride/*[
92 node-name(.) = node-name($overriding) and
93 f:componentName(.) = f:componentName($overriding) ]"/>
94 <xsl:choose>
95 <xsl:when test="count($overridden) > 0">
96 <!--* do nothing; this element has already been copied *-->
97 </xsl:when>
98 <xsl:when test="count($overridden) = 0">
99 <!--* copy this element, it isn't already there *-->
100 <xsl:copy-of select="."/>
101 </xsl:when>
102 </xsl:choose>
103 </xsl:template>
104
105
106 <xsl:function name="f:componentName" as="xs:QName?">
107 <xsl:param name="component" as="element()"/>
108 <xsl:sequence
109 select="if ($component/@name) then QName($component/ancestor::xs:schema/@targetNamespace, $component/@name) else ()"/>
110 </xsl:function>
111
112 </xsl:transform>