1
<?xml version="1.0"?>
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
                version="1.0">
4
  <xsl:output method="xml" indent="yes"/>
5
  <xsl:param name="lang" />   
6
  <xsl:param name="source" />   
7
8
  <xsl:template match="processing-instruction()" />
9
  
10
  <xsl:template match="/typesystem">
11
    <xsl:copy>
12
      <xsl:for-each select="@*">
13
        <xsl:copy>
14
          <xsl:value-of select="." />
15
        </xsl:copy>
16
      </xsl:for-each>
17
18
      <xsl:for-each select="document($source)/typesystem/@*">
19
        <xsl:copy>
20
          <xsl:value-of select="." />
21
        </xsl:copy>
22
      </xsl:for-each>
23
  
24
      <xsl:variable name="other" select="document($source)/typesystem/*[not(self::object-type | self::value-type | self::interface-type | self::namespace-type)]" />  
25
      <xsl:if test="$other">
26
          <xsl:choose>
27
          <xsl:when test="$lang != ''">
28
            <xsl:element name="language">
29
              <xsl:attribute name="name" ><xsl:value-of select="$lang" /></xsl:attribute>
30
              <xsl:copy-of select="$other" />
31
            </xsl:element>
32
          </xsl:when>
33
          <xsl:otherwise>
34
             <xsl:copy-of select="$other" />
35
          </xsl:otherwise>
36
        </xsl:choose>
37
      </xsl:if>
38
39
      <xsl:apply-templates select="node()" />
40
      
41
    </xsl:copy>
42
  </xsl:template>
43
44
45
46
  <xsl:template match="/typesystem/*[self::object-type | self::value-type | self::interface-type | self::namespace-type]">
47
    <xsl:variable name="name" select="name()" />
48
    <xsl:copy>
49
      <xsl:for-each select="@*">
50
        <xsl:copy>
51
          <xsl:value-of select="." />
52
        </xsl:copy>
53
      </xsl:for-each>
54
55
      <xsl:apply-templates select="node()" />
56
      
57
      <xsl:variable name="other" select="document($source)/typesystem/*[name() = $name][@name = current()/@name]" />
58
      <xsl:if test="$other">
59
        <xsl:choose>
60
          <xsl:when test="$lang != ''">
61
          <xsl:element name="language">
62
            <xsl:attribute name="name" ><xsl:value-of select="$lang" /></xsl:attribute>
63
            <xsl:copy-of select="$other/node()" />  
64
          </xsl:element>
65
          </xsl:when>
66
          <xsl:otherwise>
67
            <xsl:copy-of select="$other/node()" />
68
          </xsl:otherwise>
69
        </xsl:choose>
70
      </xsl:if>
71
    </xsl:copy>
72
  </xsl:template>
73
74
  <!-- Plain identity transform. -->
75
  <xsl:template match="@*|node()">
76
    <xsl:copy>
77
      <xsl:apply-templates select="@*"/>
78
      <xsl:apply-templates select="node()"/>
79
    </xsl:copy>
80
  </xsl:template>
81
82
</xsl:stylesheet>