Project

Profile

Help

How to connect?
Download (3.13 KB) Statistics
| Branch: | Tag: | Revision:

he / latest10 / hej / net / sf / saxon / data / chameleon.xsl @ 02f8308b

1
<!-- Transformation to implement chameleon include -->
2
<!-- Copied from Appendix F.1 of the XSD 1.1 Candidate Recommendation dated 21 July 2011 -->
3
<!-- Modified to make it non-schema-aware, and to fix bug 14448 -->
4

    
5
<xsl:transform version="2.0"
6
               xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
7
               xmlns:xs="http://www.w3.org/2001/XMLSchema"
8
               xmlns:f="http://www.w3.org/2008/05/XMLSchema-misc">
9

    
10
    <xsl:param name="newTargetNamespace" as="xs:anyURI" required="yes"/>
11
    <xsl:param name="prefixForTargetNamespace" as="xs:NCName" select="f:generateUniquePrefix(., 0)"/>
12
    <xsl:param name="xmlBase" as="xs:anyURI" select="base-uri(/)"/>
13

    
14
    <xsl:template match="@*|node()">
15
        <xsl:copy>
16
            <xsl:apply-templates select="@*|node()"/>
17
        </xsl:copy>
18
    </xsl:template>
19

    
20
    <xsl:template match="xs:include | xs:import | xs:redefine | xs:override">
21
        <xsl:copy>
22
            <xsl:apply-templates select="@*"/>
23
            <xsl:attribute name="xml:base" select="$xmlBase"/>
24
            <xsl:apply-templates select="node()"/>
25
        </xsl:copy>
26
    </xsl:template>
27

    
28
    <xsl:template match="xs:schema">
29
        <xsl:copy>
30
            <xsl:namespace name="{$prefixForTargetNamespace}" select="$newTargetNamespace"/>
31
            <xsl:apply-templates select="@*"/>
32
            <xsl:attribute name="targetNamespace" select="$newTargetNamespace"/>
33
            <xsl:apply-templates/>
34
        </xsl:copy>
35
    </xsl:template>
36

    
37
    <xsl:template match="@ref | @type | @base | @refer | @itemType | @defaultAttributes">
38
        <xsl:choose>
39
            <xsl:when test=". castable as xs:NCName">
40
                <xsl:attribute name="{name()}"
41
                               select="concat($prefixForTargetNamespace, ':', .)"/>
42
            </xsl:when>
43
            <xsl:otherwise>
44
                <xsl:copy/>
45
            </xsl:otherwise>
46
        </xsl:choose>
47
    </xsl:template>
48

    
49
    <xsl:template match="@memberTypes | @substitutionGroup | @notQName">
50
        <xsl:variable name="context" select=".."/>
51
        <xsl:variable name="values" as="xs:string+">
52
            <xsl:for-each select="tokenize(., '\s+')">
53
                <xsl:choose>
54
                    <xsl:when test=". castable as xs:NCName">
55
                        <xsl:sequence select="concat($prefixForTargetNamespace, ':', .)"/>
56
                    </xsl:when>
57
                    <xsl:otherwise>
58
                        <xsl:sequence select="."/>
59
                    </xsl:otherwise>
60
                </xsl:choose>
61
            </xsl:for-each>
62
        </xsl:variable>
63
        <xsl:attribute name="{name()}" select="$values"/>
64
    </xsl:template>
65

    
66

    
67
    <xsl:function name="f:generateUniquePrefix" as="xs:NCName">
68
        <xsl:param name="xsd"/>
69
        <xsl:param name="try" as="xs:integer"/>
70
        <xsl:variable name="disallowed" select="distinct-values($xsd//*/in-scope-prefixes(.))"/>
71
        <xsl:variable name="candidate" select="xs:NCName(concat('p', $try))"/>
72
        <xsl:sequence select="if ($candidate = $disallowed)
73
                             then f:generateUniquePrefix($xsd, $try+1)
74
                             else $candidate"/>
75
    </xsl:function>
76

    
77
</xsl:transform>
(4-4/14)