05e1b279d1a87ea5c9624e7869a2b1954c084a87
[iot2.git] / tree.xsl
1 <?xml version="1.0" encoding="UTF-8"?>
2 <xsl:stylesheet version="1.0" 
3                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4                 xmlns:exsl="http://exslt.org/common"
5                 >
6 <xsl:output method="xml" version="1.0" encoding="UTF-8" />
7
8 <xsl:include href="tree-view.xsl"/>
9
10 <xsl:template match="blacklist"  mode="flatten" />
11
12 <xsl:template match="document"  mode="flatten">
13       <xsl:apply-templates  mode="flatten" select="parsetree"/>
14 </xsl:template>
15
16 <xsl:template match="nonterminal" mode="flatten">
17   <xsl:variable name="temp" select="@id" />
18   <xsl:choose>
19     
20     <xsl:when test="count(*)=3 and contains($temp,'expr') and *[contains(@id,'expr')]"> 
21       <xsl:apply-templates  mode="flatten"/>
22     </xsl:when>
23
24     <!-- collapses degenerated trees like lists, conserving the blacklist subtrees-->
25     <xsl:when test="../@id = @id and count(/document/blacklist[1]/symbol[text() = $temp])=0"> 
26       <xsl:apply-templates  mode="flatten"/>
27     </xsl:when>
28
29     <!-- collapses unary productions -->
30     <xsl:when test="count(*)=3 and count(/document/blacklist[1]/symbol[text() = $temp])=0"> 
31       <xsl:apply-templates  mode="flatten"/>
32     </xsl:when>
33
34     <xsl:otherwise>
35       <xsl:element name="{@id}" >
36         <xsl:attribute name="variant"><xsl:value-of select="@variant" /></xsl:attribute>
37         <xsl:apply-templates mode="flatten"/>
38       </xsl:element>
39     </xsl:otherwise>
40
41   </xsl:choose>
42 </xsl:template>
43
44 <xsl:template match="terminal" mode="flatten">
45   <xsl:element name="{@id}">
46     <xsl:apply-templates  mode="flatten"/>
47   </xsl:element>
48 </xsl:template>
49
50 <xsl:template match="/">
51  <xsl:variable name="flatten">
52      <xsl:apply-templates  mode="flatten"/>
53  </xsl:variable>
54  <xsl:variable name="rendered">
55     <xsl:apply-templates mode="rendered" select="exsl:node-set($flatten)"/>
56  </xsl:variable>
57
58  <!--xsl:copy-of select="$rendered" /-->
59  <xsl:copy-of select="$flatten" />
60 </xsl:template>
61
62
63 </xsl:stylesheet>