-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatch_wurfl.xsl
134 lines (128 loc) · 4.13 KB
/
patch_wurfl.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
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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="UTF-8" indent="yes" cdata-section-elements="statement"/>
<!--
patch WURFL with overlay XML
send comments, questions to roland guelle <[email protected]>
-->
<xsl:param name="file">patchfile.xml</xsl:param>
<xsl:param name="patch_file" select="document($file,/wurfl_patch)"/>
<xsl:template match="/">
<wurfl>
<xsl:copy-of select="/wurfl/version"/>
<xsl:apply-templates select="/wurfl/devices"/>
</wurfl>
</xsl:template>
<xsl:template match="devices">
<xsl:copy>
<xsl:apply-templates/>
<xsl:if test="$patch_file/wurfl_patch/devices/device[not(@id = current()/device/@id)]">
<xsl:comment> devices from patchfile <xsl:value-of select="$file"/> </xsl:comment>
<xsl:apply-templates select="$patch_file/wurfl_patch/devices/device[not(@id = current()/device/@id)]">
<xsl:with-param name="patch_overlay" select="$patch_file/none"/>
</xsl:apply-templates>
</xsl:if>
</xsl:copy>
</xsl:template>
<!--
patch devices
-->
<xsl:template match="device">
<xsl:param name="patch_overlay" select="$patch_file"/>
<xsl:variable name="patch" select="$patch_overlay/wurfl_patch/devices/device[@id = current()/@id]"/>
<!--
copy comments between current and preceding node
-->
<xsl:copy-of select="$patch/preceding-sibling::comment()[following-sibling::device[1]/@id = current()/@id]"/>
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:copy-of select="$patch/@*"/>
<!--
copy groups unknown in WURFL
-->
<xsl:apply-templates select="$patch/group[not(@id = current()/group/@id)]">
<xsl:with-param name="patch" select="$patch"/>
</xsl:apply-templates>
<!--
copy groups known in WURFL
-->
<xsl:apply-templates>
<xsl:with-param name="patch" select="$patch"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<!--
group elements
-->
<xsl:template match="group">
<!--
select="." is only a fake
if WURFL structure is broken (group as child of devices) XSL generate a 'Evaluating variable patch_group failed'
-->
<xsl:param name="patch" select="."/>
<xsl:variable name="patch_group" select="$patch/group[@id = current()/@id]"/>
<xsl:choose>
<!--
check if a patch is available
-->
<xsl:when test="$patch/group[@id = current()/@id]">
<!--
copy comments between current and preceding node
-->
<xsl:copy-of select="$patch_group/preceding-sibling::comment()[following-sibling::group[1]/@id = current()/@id]"/>
<xsl:copy>
<xsl:copy-of select="@*"/>
<!--
copy and overwrite patched attributes
-->
<xsl:copy-of select="$patch_group/@*"/>
<!--
copy capabilities unknown in WURFL
-->
<xsl:apply-templates select="$patch_group/capability[not(@name = current()/capability/@name)]">
<xsl:with-param name="patch" select="$patch_group"/>
</xsl:apply-templates>
<!--
copy capabilities known in WURFL
-->
<xsl:apply-templates>
<xsl:with-param name="patch" select="$patch_group"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<!--
copy capabilities untouched
-->
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates>
<xsl:with-param name="patch" select="$patch_group"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
create capability
-->
<xsl:template match="capability">
<xsl:param name="patch" select="."/>
<xsl:copy-of select="$patch/capability[@name = current()/@name]/preceding-sibling::comment()[following-sibling::capability[1]/@name = current()/@name]"/>
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:copy-of select="$patch/capability[@name = current()/@name]/@*"/>
</xsl:copy>
</xsl:template>
<!--
copy elements
-->
<xsl:template match="*|@*|text()|comment()">
<xsl:param name="patch"/>
<xsl:copy>
<xsl:apply-templates>
<xsl:with-param name="patch" select="$patch"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>