Statistics
| Revision:

root / tmp / org.txm.core / res / org / txm / xml / xsl / tei / fo2 / tei-makecolspec.xsl @ 187

History | View | Annotate | Download (5.4 kB)

1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet 
3
                xmlns:fotex="http://www.tug.org/fotex"
4
                xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
5
                xmlns="http://www.w3.org/1999/XSL/Format"
6
                xmlns:rng="http://relaxng.org/ns/structure/1.0"
7
                xmlns:tei="http://www.tei-c.org/ns/1.0"
8
                xmlns:teix="http://www.tei-c.org/ns/Examples"
9
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
10
                exclude-result-prefixes=" a rng tei teix"
11
                version="2.0">
12
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
13
      <desc>
14
         <p>
15
    TEI stylesheet for making table specifications, making XSL-FO output.
16
      </p>
17
         <p>This software is dual-licensed:
18

    
19
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
20
Unported License http://creativecommons.org/licenses/by-sa/3.0/ 
21

    
22
2. http://www.opensource.org/licenses/BSD-2-Clause
23
		
24
All rights reserved.
25

    
26
Redistribution and use in source and binary forms, with or without
27
modification, are permitted provided that the following conditions are
28
met:
29

    
30
* Redistributions of source code must retain the above copyright
31
notice, this list of conditions and the following disclaimer.
32

    
33
* Redistributions in binary form must reproduce the above copyright
34
notice, this list of conditions and the following disclaimer in the
35
documentation and/or other materials provided with the distribution.
36

    
37
This software is provided by the copyright holders and contributors
38
"as is" and any express or implied warranties, including, but not
39
limited to, the implied warranties of merchantability and fitness for
40
a particular purpose are disclaimed. In no event shall the copyright
41
holder or contributors be liable for any direct, indirect, incidental,
42
special, exemplary, or consequential damages (including, but not
43
limited to, procurement of substitute goods or services; loss of use,
44
data, or profits; or business interruption) however caused and on any
45
theory of liability, whether in contract, strict liability, or tort
46
(including negligence or otherwise) arising in any way out of the use
47
of this software, even if advised of the possibility of such damage.
48
</p>
49
         <p>Author: See AUTHORS</p>
50
         <p>Id: $Id: tei-makecolspec.xsl 9646 2011-11-05 23:39:08Z rahtz $</p>
51
         <p>Copyright: 2011, TEI Consortium</p>
52
      </desc>
53
   </doc>
54
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
55
      <desc>[fo] </desc>
56
   </doc>
57
  <xsl:template name="calculateTableSpecs">
58
      <xsl:variable name="tds">
59
         <xsl:for-each select=".//tei:cell">
60
            <xsl:variable name="stuff">
61
               <xsl:apply-templates/>
62
            </xsl:variable>
63
            <cell>
64
               <xsl:attribute name="col">
65
                  <xsl:number/>
66
               </xsl:attribute>
67
               <xsl:value-of select="string-length($stuff)"/>
68
            </cell>
69
         </xsl:for-each>
70
      </xsl:variable>
71
      <xsl:variable name="total">
72
         <xsl:value-of select="sum($tds/cell)"/>
73
      </xsl:variable>
74
      <xsl:for-each select="$tds/cell">
75
         <xsl:sort select="@col" data-type="number"/>
76
         <xsl:variable name="c" select="@col"/>
77
         <xsl:if test="not(preceding-sibling::cell[$c=@col])">
78
            <xsl:variable name="len">
79
               <xsl:value-of select="sum(following-sibling::cell[$c=@col]) + current()"/>
80
            </xsl:variable>
81
            <xsl:text>&#10;</xsl:text>
82
            <table-column column-number="{@col}" column-width="{$len div $total * 100}%">
83
               <xsl:if test="$foEngine='passivetex'">
84
                  <xsl:attribute name="column-align" namespace="http://www.tug.org/fotex">L</xsl:attribute>
85
               </xsl:if>
86
            </table-column>
87
         </xsl:if>
88
      </xsl:for-each>
89
      <xsl:text>&#10;</xsl:text>
90
  </xsl:template>
91
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
92
      <desc>[fo] </desc>
93
   </doc>
94
  <xsl:template name="deriveColSpecs">
95
      <xsl:variable name="no">
96
         <xsl:call-template name="generateTableID"/>
97
      </xsl:variable>
98
      <xsl:choose>
99
         <xsl:when test="$readColSpecFile">
100
            <xsl:variable name="specs">
101
               <xsl:value-of select="count($tableSpecs/Info/TableSpec[$no=@xml:id])"/>
102
            </xsl:variable>
103
            <xsl:choose>
104
               <xsl:when test="$specs &gt; 0">
105
                  <xsl:for-each select="$tableSpecs/Info/TableSpec[$no=@xml:id]/table-column">
106
                     <xsl:copy-of select="."/>
107
                  </xsl:for-each>
108
               </xsl:when>
109
               <xsl:otherwise>
110
<!--
111
 <xsl:message>Build specs for Table <xsl:value-of select="$no"/></xsl:message>
112
-->
113
            <xsl:call-template name="calculateTableSpecs"/>
114
               </xsl:otherwise>
115
            </xsl:choose>
116
         </xsl:when>
117
         <xsl:otherwise>
118
<!--
119
 <xsl:message>Build specs for Table <xsl:value-of select="$no"/></xsl:message>
120
-->
121
        <xsl:call-template name="calculateTableSpecs"/>
122
         </xsl:otherwise>
123
      </xsl:choose>
124
  </xsl:template>
125
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
126
      <desc>[fo] </desc>
127
   </doc>
128
  <xsl:template name="generateTableID">
129
      <xsl:choose>
130
         <xsl:when test="@xml:id">
131
            <xsl:value-of select="@xml:id"/>
132
         </xsl:when>
133
         <xsl:otherwise>
134
            <xsl:text>Table-</xsl:text>
135
            <xsl:number level="any"/>
136
         </xsl:otherwise>
137
      </xsl:choose>
138
  </xsl:template>
139
</xsl:stylesheet>