File size: 3,172 Bytes
6d12932
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<?xml version="1.0" encoding="UTF-8"?>
<!--

  - Integrate the 'default' groupings with any custom groupings, sorting ones that start with '-' to intermix with other 'standard' groupings

  -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:f="http://hl7.org/fhir" exclude-result-prefixes="f">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="f:definition">
    <xsl:copy>
      <xsl:apply-templates select="@*|f:extension|f:modifierExtension"/>
      <xsl:call-template name="doGroupings"/>
      <xsl:apply-templates select="node()[not(self::f:extension or self::f:modifierExtension or self::f:grouping or self::f:groups)]"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template name="doGroupings">
    <xsl:apply-templates select="f:grouping[not(starts-with(@id, '-'))]"/>
    <xsl:call-template name="doGrouping">
      <xsl:with-param name="prefix" select="'-req'"/>
    </xsl:call-template>
    <xsl:call-template name="doGrouping">
      <xsl:with-param name="prefix" select="'-dyn'"/>
    </xsl:call-template>
    <xsl:call-template name="doGrouping">
      <xsl:with-param name="prefix" select="'-ka'"/>
    </xsl:call-template>
    <xsl:call-template name="doGrouping">
      <xsl:with-param name="prefix" select="'-str'"/>
    </xsl:call-template>
    <xsl:call-template name="doGrouping">
      <xsl:with-param name="prefix" select="'-term'"/>
    </xsl:call-template>
    <xsl:call-template name="doGrouping">
      <xsl:with-param name="prefix" select="'-map'"/>
    </xsl:call-template>
    <xsl:call-template name="doGrouping">
      <xsl:with-param name="prefix" select="'-test'"/>
    </xsl:call-template>
    <xsl:call-template name="doGrouping">
      <xsl:with-param name="prefix" select="'-ex'"/>
    </xsl:call-template>
    <xsl:call-template name="doGrouping">
      <xsl:with-param name="prefix" select="'-other'"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template name="doGrouping">
    <xsl:param name="prefix"/>
    <xsl:for-each select="f:groups/f:grouping[starts-with(@id, $prefix)]">
      <xsl:copy>
        <xsl:choose>
          <xsl:when test="parent::f:groups/parent::*/f:grouping[@id=current()/@id]">
            <xsl:for-each select="parent::f:groups/parent::*/f:grouping[@id=current()/@id]">
              <xsl:apply-templates select="@*|node()"/>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:apply-templates select="@*|node()"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:copy>
    </xsl:for-each>
    <xsl:for-each select="f:grouping[starts-with(@id, $prefix)]">
      <xsl:if test="not(parent::*/f:groups/f:grouping[@id=current()/@id])">
        <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>