summaryrefslogtreecommitdiff
path: root/source/02_data/branches.xsl
blob: ce661cc4e3281c584c4b62bcb2c3cb2a93825673 (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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
	version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xalan="http://xml.apache.org/xalan"
	xmlns:InputXSLT="function.inputxslt.application"
	exclude-result-prefixes="xalan InputXSLT"
>

<xsl:include href="[utility/datasource.xsl]"/>

<xsl:variable name="meta">
	<datasource type="main"  mode="full" source="01_raw/tree.xml" target="tree"/>
	<target     mode="plain" value="branches.xml"/>
</xsl:variable>

<xsl:template match="branch | leaf" mode="serialize">
	<xsl:apply-templates select="parent::branch" mode="serialize"/>
	<xsl:text>/</xsl:text>
	<xsl:value-of select="@name"/>
</xsl:template>

<xsl:template match="@*|node()" mode="include">
	<xsl:copy>
		<xsl:apply-templates select="@*|node()" mode="include"/>
	</xsl:copy>
</xsl:template>

<xsl:template match="leaf" mode="include">
	<xsl:apply-templates select="node()" mode="include"/>
</xsl:template>

<xsl:template match="leaf" mode="digest">
	<node name="{@name}">
		<title>
			<xsl:value-of select="title"/>
		</title>
		<digest size="{string-length(content/p[normalize-space(.)][1])}">
			<xsl:copy-of select="content/p[normalize-space(.)][1]/node()"/>
		</digest>
	</node>
</xsl:template>

<xsl:template match="leaf">
	<xsl:variable name="name" select="@name"/>

	<xsl:if test="not(preceding-sibling::branch[@name = $name])">
		<xsl:apply-templates select="." mode="digest"/>
	</xsl:if>
</xsl:template>

<xsl:template match="branch" mode="digest">
	<xsl:variable name="name" select="@name"/>

	<xsl:apply-templates select="following-sibling::leaf[@name = $name]" mode="digest"/>
</xsl:template>

<xsl:template match="branch">
	<xsl:variable name="path">
		<xsl:apply-templates select="." mode="serialize"/>
	</xsl:variable>

	<entry handle="{$path}">
		<xsl:variable name="name" select="@name"/>

		<payload>
			<xsl:apply-templates select="following-sibling::leaf[@name = $name]" mode="include"/>
		</payload>

		<branches>
			<xsl:apply-templates select="branch" mode="digest"/>
		</branches>

		<leaves>
			<xsl:apply-templates select="leaf"/>
		</leaves>
	</entry>
</xsl:template>

<xsl:template match="tree">
	<xsl:apply-templates select="//branch"/>
</xsl:template>

</xsl:stylesheet>