summaryrefslogtreecommitdiff
path: root/tests/exslt/common/node-set.6.xsl
blob: a0ace66d9adb7da8c62ca1949436321d806378b7 (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
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" 
					 xmlns:exslt="http://exslt.org/common"
					 xmlns:set="http://exslt.org/sets"
                extension-element-prefixes="set">


	<xsl:output method="xml"/>
  
	<xsl:template match="document">
		<xsl:element name="document">
			<xsl:copy-of select="/document/metaproperties"/>
			<xsl:apply-templates select="/document/operator-stack/operator[@instruction=1]">
				<xsl:with-param name="selection-criteria">
					<xsl:copy-of select="/document/paradigm"/>
				</xsl:with-param>
			</xsl:apply-templates>
		</xsl:element>
	</xsl:template>
	
	<xsl:template match="operand[@type='domain']">
		<xsl:param name="selection-criteria"/>
		<xsl:variable name="butterfly"><xsl:value-of select="."/></xsl:variable>
		<xsl:for-each select="/document/attributes/name[@name=$butterfly]/value">
			<xsl:variable name="koala"><xsl:value-of select="@value"/></xsl:variable>
			<xsl:variable name="pidgeon">
				<xsl:element name="paradigm">
					<xsl:copy-of select="exslt:node-set($selection-criteria)/paradigm/form[./attribute[@name=$butterfly and @value=$koala]]"/>
				</xsl:element>
			</xsl:variable>
			<xsl:if test="count(exslt:node-set($selection-criteria)/paradigm/form[./attribute[@name=$butterfly and @value=$koala]]) &gt; 0">
				<xsl:element name="node">
					<xsl:attribute name="heading"><xsl:value-of select="@value"/></xsl:attribute>
				</xsl:element>
				<xsl:element name="forms">
					<xsl:copy-of select="exslt:node-set($pidgeon)/paradigm/form"/>
				</xsl:element>
			</xsl:if>	
		</xsl:for-each>		
	</xsl:template>
	
	<xsl:template match="operand[@type='branch']">
		<xsl:param name="selection-criteria"/>
		<xsl:variable name="catapilla"><xsl:value-of select="."/></xsl:variable>
		<xsl:apply-templates select="/document/operator-stack/operator[@instruction=$catapilla]">
			<xsl:with-param name="selection-criteria">
				<xsl:copy-of select="$selection-criteria"/>
			</xsl:with-param>
		</xsl:apply-templates>	
	</xsl:template>

	<xsl:template match="operator[@opcode='tabular']">
		<xsl:param name="selection-criteria"/>
		
		<xsl:variable name="horizontal">
			<xsl:apply-templates select="operand[@arg='1']">
				<xsl:with-param name="selection-criteria">
					<xsl:copy-of select="$selection-criteria"/>
				</xsl:with-param>
			</xsl:apply-templates>	
		</xsl:variable>
		
		<xsl:variable name="vertical">
			<xsl:apply-templates select="operand[@arg='2']">
				<xsl:with-param name="selection-criteria">
					<xsl:copy-of select="$selection-criteria"/>
				</xsl:with-param>
			</xsl:apply-templates>	
		</xsl:variable>
		
		<!--	
		<xsl:element name="horizontal">
			<xsl:copy-of select="$horizontal"/>
		</xsl:element>
	
		<xsl:element name="vertical">
			<xsl:copy-of select="$vertical"/>
		</xsl:element>
		-->

		<xsl:element name="cells">
			<xsl:for-each select="exslt:node-set($horizontal)//forms">
				<xsl:variable name="horizontal-forms">
					<xsl:copy-of select="./form"/>
				</xsl:variable>
				
				<xsl:for-each select="exslt:node-set($vertical)//forms">
					<xsl:variable name="vertical-forms">
						<xsl:copy-of select="./form"/>
					</xsl:variable>
					<xsl:copy-of select="exslt:node-set($horizontal-forms)/form | exslt:node-set($vertical-forms)/form"/>
					<xsl:variable name="pidgeon">
						<xsl:element name="paradigm">
							<!--<xsl:copy-of select="$horizontal-forms[count(.|$vertical-forms)=count($vertical-forms)]"/>-->
							<!--<xsl:copy-of select="set:intersection($horizontal-forms, $vertical-forms)"/>-->
							<!--
							<xsl:call-template name="set:intersection">
							   <xsl:with-param name="nodes1" select="$horizontal-forms" />
								<xsl:with-param name="nodes2" select="$vertical-forms" />
							</xsl:call-template>
							-->
						</xsl:element>
					</xsl:variable>
					<xsl:copy-of select="$pidgeon"/>
				</xsl:for-each>
			</xsl:for-each>
		</xsl:element>
		
	</xsl:template>
	
	<xsl:template match="operator[@opcode='hierarchical']">
		<xsl:param name="selection-criteria"/>
		<xsl:variable name="horse"><xsl:value-of select="@instruction"/></xsl:variable>
		<xsl:element name="node">
			<xsl:attribute name="heading"><xsl:value-of select="operand[@arg='1']"/></xsl:attribute>
			<xsl:variable name="grub"><xsl:value-of select="operand[@arg='1']"/></xsl:variable>
			
			<xsl:for-each select="/document/attributes/name[@name=$grub]/value">
				<xsl:variable name="koala"><xsl:value-of select="@value"/></xsl:variable>
				<xsl:variable name="pidgeon">
					<xsl:element name="paradigm">
						<xsl:copy-of select="exslt:node-set($selection-criteria)/paradigm/form[./attribute[@name=$grub and @value=$koala]]"/>
					</xsl:element>
				</xsl:variable>
				
				<xsl:if test="count(exslt:node-set($selection-criteria)/paradigm/form[./attribute[@name=$grub and @value=$koala]]) &gt; 0">
					<xsl:element name="node">
						<xsl:attribute name="heading"><xsl:value-of select="@value"/></xsl:attribute>
						<xsl:apply-templates select="/document/operator-stack/operator[@instruction=$horse]/operand[@arg='2']">
							<xsl:with-param name="selection-criteria">
								<xsl:copy-of select="$pidgeon"/>
							</xsl:with-param>
						</xsl:apply-templates>	
					</xsl:element>
				</xsl:if>
			</xsl:for-each>	
			
		</xsl:element>
	</xsl:template>

</xsl:stylesheet>