-
Notifications
You must be signed in to change notification settings - Fork 8
/
merge.xsl
82 lines (69 loc) · 2.49 KB
/
merge.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
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="lang" />
<xsl:param name="source" />
<xsl:template match="processing-instruction()" />
<xsl:template match="/typesystem">
<xsl:copy>
<xsl:for-each select="@*">
<xsl:copy>
<xsl:value-of select="." />
</xsl:copy>
</xsl:for-each>
<xsl:for-each select="document($source)/typesystem/@*">
<xsl:copy>
<xsl:value-of select="." />
</xsl:copy>
</xsl:for-each>
<xsl:variable name="other" select="document($source)/typesystem/*[not(self::object-type | self::value-type | self::interface-type | self::namespace-type)]" />
<xsl:if test="$other">
<xsl:choose>
<xsl:when test="$lang != ''">
<xsl:element name="language">
<xsl:attribute name="name" ><xsl:value-of select="$lang" /></xsl:attribute>
<xsl:copy-of select="$other" />
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$other" />
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="/typesystem/*[self::object-type | self::value-type | self::interface-type | self::namespace-type]">
<xsl:variable name="name" select="name()" />
<xsl:copy>
<xsl:for-each select="@*">
<xsl:copy>
<xsl:value-of select="." />
</xsl:copy>
</xsl:for-each>
<xsl:apply-templates select="node()" />
<xsl:variable name="other" select="document($source)/typesystem/*[name() = $name][@name = current()/@name]" />
<xsl:if test="$other">
<xsl:choose>
<xsl:when test="$lang != ''">
<xsl:element name="language">
<xsl:attribute name="name" ><xsl:value-of select="$lang" /></xsl:attribute>
<xsl:copy-of select="$other/node()" />
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$other/node()" />
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:copy>
</xsl:template>
<!-- Plain identity transform. -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>