summaryrefslogtreecommitdiff
path: root/writerfilter/source/ooxml/attrsprm.xsl
blob: 9351b1b874c920fd01477325ad4b7a275fa85038 (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
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
135
136
137
138
139
140
141
142
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet 
    version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:rng="http://relaxng.org/ns/structure/1.0"
    xmlns:xalan="http://xml.apache.org/xalan"
    exclude-result-prefixes = "xalan"
    xml:indent="true">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="no"/>

  <xsl:include href="factorytools.xsl"/>
  
  <xsl:template match="/">
    <class>
      <xsl:for-each select="//rng:define[@name='CT_FFData']">
	<xsl:call-template name="sprm"/>
	<xsl:call-template name="attribute"/>
      </xsl:for-each>
    </class>
  </xsl:template>

  <xsl:template name="sprminner">
    <xsl:variable name="defname" select="@name"/>
    <xsl:for-each select=".//rng:ref[not(ancestor::rng:element or ancestor::rng:attribute)]">
      <xsl:call-template name="sprminner"/>
    </xsl:for-each>
    <xsl:for-each select=".//rng:element">
      <xsl:for-each select="rng:ref">
	<xsl:variable name="refname" select="@name"/>
	<xsl:for-each select="ancestor::namespace/rng:grammar/rng:define[@name=$refname]">
	  <xsl:call-template name="sprminner"/>
	</xsl:for-each>
      </xsl:for-each>      
      <element>
	<xsl:variable name="elementname" select="@name"/>
	<xsl:attribute name="name">
	  <xsl:value-of select="@name"/>
	</xsl:attribute>
	<xsl:for-each select="rng:ref">
	  <xsl:variable name="refname" select="@name"/>
	  <xsl:for-each select="ancestor::namespace/resource[@name=$refname]">
	    <xsl:attribute name="action">
	      <xsl:choose>
		<xsl:when test="@resource='Properties'">
		  <xsl:text>resolve</xsl:text>
		</xsl:when>
		<xsl:otherwise>
		  <xsl:text>set</xsl:text>
		</xsl:otherwise>
	      </xsl:choose>
	    </xsl:attribute>
	  </xsl:for-each>
	  <xsl:for-each select="ancestor::namespace/resource[@name=$defname]">
	    <xsl:for-each select="element[@name=$elementname]">
	      <xsl:attribute name="id">
		<xsl:call-template name="idtoqname">
		  <xsl:with-param name="id">
		    <xsl:value-of select="@tokenid"/>
		  </xsl:with-param>
		</xsl:call-template>
	      </xsl:attribute>
	    </xsl:for-each>
	  </xsl:for-each>
	</xsl:for-each>
      </element>	
    </xsl:for-each>
  </xsl:template>

  <xsl:template name="sprm">
    <sprm>
      <xsl:call-template name="sprminner"/>
    </sprm>
  </xsl:template>

  <xsl:template name="attributeinner">
    <xsl:param name="parent"/>
    <xsl:for-each select=".//rng:ref[not(ancestor::rng:element or ancestor::rng:attribute)]">
      <xsl:variable name="refname" select="@name"/>
      <xsl:comment><xsl:value-of select="$newparent"/></xsl:comment>
      <xsl:for-each select="ancestor::namespace/rng:grammar/rng:define[@name=$refname]">
	<xsl:call-template name="attributeinner">
	  <xsl:with-param name="parent" select="$parent"/>
	</xsl:call-template>
      </xsl:for-each>
    </xsl:for-each>
    <xsl:for-each select=".//rng:element">
      <xsl:variable name="newparent">
	<xsl:if test="string-length($parent)">
	  <xsl:value-of select="$parent"/>
	  <xsl:text>:</xsl:text>
	</xsl:if>
	<xsl:value-of select="@name"/>
      </xsl:variable>
      <xsl:for-each select="rng:ref">
	<xsl:variable name="refname" select="@name"/>
	<xsl:for-each select="ancestor::namespace/rng:grammar/rng:define[@name=$refname]">
	  <xsl:call-template name="attributeinner">
	    <xsl:with-param name="parent" select="$newparent"/>
	  </xsl:call-template>
	</xsl:for-each>
      </xsl:for-each>
    </xsl:for-each>
    <xsl:variable name="defname" select="@name"/>
    <xsl:variable name="resource">
      <xsl:for-each select="ancestor::namespace/resource[@name=$defname]">
	<xsl:value-of select="@resource"/>
      </xsl:for-each>
    </xsl:variable>
    <xsl:if test="$resource='Properties'">
      <xsl:for-each select=".//rng:attribute">
	<xsl:variable name="attrname" select="@name"/>
	<attribute>	  
	  <xsl:attribute name="name">
	    <xsl:if test="string-length($parent) > 0">
	      <xsl:value-of select="$parent"/>
	      <xsl:text>:</xsl:text>
	    </xsl:if>
	    <xsl:value-of select="$attrname"/>
	  </xsl:attribute>
	  <xsl:for-each select="ancestor::namespace/resource[@name=$defname]">
	    <xsl:for-each select="attribute[@name=$attrname]">
	      <xsl:attribute name="id">
		<xsl:call-template name="idtoqname">
		  <xsl:with-param name="id">
		    <xsl:value-of select="@tokenid"/>
		  </xsl:with-param>
		</xsl:call-template>
	      </xsl:attribute>
	    </xsl:for-each>
	  </xsl:for-each>
	</attribute>
      </xsl:for-each>
    </xsl:if>
  </xsl:template>

  <xsl:template name="attribute">
    <attribute>
      <xsl:call-template name="attributeinner"/>
    </attribute>
  </xsl:template>

</xsl:stylesheet>