/
definitions.xsl
92 lines (72 loc) · 3.07 KB
/
definitions.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:out="dummy"
xmlns:c="http://evanlenz.net/carrot"
exclude-result-prefixes="out c">
<!-- NOTE: The default mode is sequence constructor mode -->
<xsl:template match="NamespaceDecl">
<xsl:namespace name="{NCName/NCName}" select="URILiteral/substring(., 2, string-length(.) - 2)"/>
</xsl:template>
<xsl:template match="VarDecl">
<out:variable name="{QName}">
<xsl:apply-templates select="TypeDeclaration"/>
<xsl:apply-templates mode="variable-value" select="c:*"/>
</out:variable>
</xsl:template>
<xsl:template match="TypeDeclaration">
<xsl:attribute name="as" select="string(SequenceType)"/>
</xsl:template>
<xsl:template mode="variable-value" match="c:XPATH">
<xsl:attribute name="select" select="c:xpath(.)"/>
</xsl:template>
<xsl:template mode="variable-value" match="VarDecl/c:SEQUENCE_CONSTRUCTOR
| ParamWithDefault/c:SEQUENCE_CONSTRUCTOR
| InitializedParam/c:SEQUENCE_CONSTRUCTOR">
<xsl:if test="not(../TypeDeclaration | ../Param/TypeDeclaration)">
<xsl:attribute name="as" select="'item()*'"/>
</xsl:if>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="FunctionDecl">
<out:function name="{FunctionName/QName}">
<xsl:apply-templates select="TypeDeclaration"/>
<xsl:apply-templates select="Expr"/>
</out:function>
</xsl:template>
<xsl:template match="ParamList/Param">
<out:param name="{QName}">
<xsl:apply-templates select="TypeDeclaration"/>
</out:param>
</xsl:template>
<xsl:template match="RuleDecl">
<out:template match="{c:xpath(Pattern)}">
<xsl:apply-templates select="ModeName[1],
Priority,
RuleParamList/ParamWithDefault"/>
<xsl:apply-templates select="Expr"/>
</out:template>
</xsl:template>
<xsl:template match="ModeName[1]">
<xsl:attribute name="mode">
<xsl:value-of select="."/>
<xsl:apply-templates select="following-sibling::ModeName"/>
</xsl:attribute>
</xsl:template>
<xsl:template match="ModeName">
<xsl:text> </xsl:text>
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="RuleDecl/Priority">
<xsl:attribute name="priority" select="."/>
</xsl:template>
<xsl:template match="ParamWithDefault">
<out:param name="{Param/QName}">
<xsl:apply-templates select="Tunnel"/>
<xsl:apply-templates mode="variable-value" select="c:*"/>
</out:param>
</xsl:template>
<xsl:template match="Tunnel">
<xsl:attribute name="tunnel" select="'yes'"/>
</xsl:template>
</xsl:stylesheet>