aboutsummaryrefslogtreecommitdiff
path: root/generate.xsl
blob: 405f940276dd9485ff4e9bd1852260277f65c21b (plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
	version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:dyn="http://exslt.org/dynamic"
	xmlns:xalan="http://xml.apache.org/xalan"
	xmlns:InputXSLT="function.inputxslt.application"
	exclude-result-prefixes="dyn xalan InputXSLT"
>

<xsl:output
	method="xml"
	omit-xml-declaration="yes"
	encoding="UTF-8"
	indent="yes"
/>

<xsl:template name="generator">
	<xsl:param name="input"/>
	<xsl:param name="transformation"/>
	<xsl:param name="target"/>

	<xsl:copy-of select="InputXSLT:generate(
		$input,
		$transformation,
		$target
	)/self::generation"/>
</xsl:template>

<xsl:template name="compiler">
	<xsl:param name="input"/>
	<xsl:param name="transformation"/>
	<xsl:param name="target_prefix"/>
	<xsl:param name="target"/>

	<xsl:variable name="resolved_target">
		<xsl:choose>
			<xsl:when test="$target/@mode = 'plain'">
				<xsl:value-of select="$target/@value"/>
			</xsl:when>
			<xsl:when test="$target/@mode = 'xpath'">
				<xsl:value-of select="dyn:evaluate($target/@value)"/>
			</xsl:when>
			<xsl:otherwise>

			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>

	<xsl:call-template name="generator">
		<xsl:with-param name="input"          select="$input"/>
		<xsl:with-param name="transformation" select="$transformation"/>
		<xsl:with-param name="target"         select="concat($target_prefix, '/', $resolved_target)"/>
	</xsl:call-template>
</xsl:template>

<xsl:template name="datasource">
	<xsl:param name="main"/>
	<xsl:param name="support"/>

	<datasource>
		<xsl:copy-of select="$main"/>
		<xsl:for-each select="$support">
			<xsl:element name="{./@target}">
				<xsl:choose>
					<xsl:when test="./@mode = 'full'">
						<xsl:copy-of select="InputXSLT:read-file(./@source)/self::file/*/*"/>
					</xsl:when>
					<xsl:otherwise>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:element>
		</xsl:for-each>
	</datasource>
</xsl:template>

<xsl:template match="/">
	<xsl:for-each select="InputXSLT:read-directory('source/')/entry[@type = 'directory']">
		<xsl:variable name="level" select="."/>

		<xsl:for-each select="InputXSLT:read-directory(./full)/entry[./extension = '.xsl']">
			<xsl:variable name="transformation" select="."/>
			<xsl:variable name="stylesheet"     select="InputXSLT:read-file($transformation/full)/self::file/*"/>
			<xsl:variable name="meta"           select="$stylesheet/self::*[name() = 'xsl:stylesheet']/*[name() = 'xsl:variable' and @name = 'meta']"/>
			<xsl:variable name="main"           select="$meta/datasource[@type = 'main']"/>

			<xsl:choose>
				<xsl:when test="$main/@mode = 'full'">
					<xsl:call-template name="compiler">
						<xsl:with-param name="input">
							<xsl:call-template name="datasource">
								<xsl:with-param name="main">
									<xsl:element name="{$main/@target}">
										<xsl:copy-of select="InputXSLT:read-file($main/@source)/self::file/*/*"/>
									</xsl:element>
								</xsl:with-param>
								<xsl:with-param name="support" select="$meta/datasource[@type = 'support']"/>
							</xsl:call-template>
						</xsl:with-param>
						<xsl:with-param name="transformation" select="$stylesheet"/>
						<xsl:with-param name="target_prefix"  select="concat('target/', $level/name)"/>
						<xsl:with-param name="target"         select="$meta/target"/>
					</xsl:call-template>
				</xsl:when>
				<xsl:when test="$main/@mode = 'iterate'">
					<xsl:variable name="datasource" select="InputXSLT:read-file($main/@source)/self::file/*"/>

					<xsl:for-each select="$datasource/entry">
						<xsl:call-template name="compiler">
							<xsl:with-param name="input">
								<xsl:call-template name="datasource">
									<xsl:with-param name="main">
										<xsl:element name="{$main/@target}">
											<xsl:copy-of select="."/>
										</xsl:element>
									</xsl:with-param>
									<xsl:with-param name="support" select="$meta/datasource[@type = 'support']"/>
								</xsl:call-template>
							</xsl:with-param>
							<xsl:with-param name="transformation" select="$stylesheet"/>
							<xsl:with-param name="target_prefix"  select="concat('target/', $level/name)"/>
							<xsl:with-param name="target"         select="$meta/target"/>
						</xsl:call-template>
					</xsl:for-each>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="compiler">
						<xsl:with-param name="input">
							<xsl:call-template name="datasource">
								<xsl:with-param name="support" select="$meta/datasource[@type = 'support']"/>
							</xsl:call-template>
						</xsl:with-param>
						<xsl:with-param name="transformation" select="$stylesheet"/>
						<xsl:with-param name="target_prefix"  select="concat('target/', $level/name)"/>
						<xsl:with-param name="target"         select="$meta/target"/>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
	</xsl:for-each>
</xsl:template>

</xsl:stylesheet>