aboutsummaryrefslogtreecommitdiffstats
path: root/test/java/org/apache/fop/accessibility/fo/fo2StructureTree.xsl
blob: 90d74a7c4a97b5e434cc85049ade70fe8c5250ee (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- $Id$ -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
  xmlns:fox="http://xmlgraphics.apache.org/fop/extensions"
  xmlns:foi="http://xmlgraphics.apache.org/fop/internal">

  <xsl:output method="xml" indent="yes"/>

  <xsl:template name="copy">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>


  <!-- Ignore fo:root -->
  <xsl:template match="fo:root">
    <structure-tree-sequence>
      <xsl:apply-templates/>
    </structure-tree-sequence>
  </xsl:template>

  <!-- fo:page-sequence maps to structure-tree -->
  <xsl:template match="fo:page-sequence">
    <structure-tree xmlns="http://xmlgraphics.apache.org/fop/intermediate">
        <xsl:apply-templates/>
    </structure-tree>
  </xsl:template>


  <!-- Declarations and Pagination and Layout Formatting Objects -->
  <xsl:template match="fo:static-content|fo:flow">
    <xsl:call-template name="copy"/>
  </xsl:template>

  <xsl:template match="fo:static-content/@flow-name|fo:flow/@flow-name">
    <xsl:choose>
      <xsl:when test=". = 'xsl-region-body' or
        . = 'xsl-region-before' or
        . = 'xsl-region-after' or
        . = 'xsl-region-start' or
        . = 'xsl-region-end' or
        . = 'xsl-before-float-separator' or
        . = 'xsl-footnote-separator'">
        <xsl:copy/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:attribute name="{local-name()}">
          <xsl:value-of select="concat('xsl-', local-name(//*[@region-name = current()]))"/>
        </xsl:attribute>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Block-level Formatting Objects -->
  <xsl:template match="fo:block|fo:block-container">
    <xsl:call-template name="copy"/>
  </xsl:template>

  <!-- Inline-level Formatting Objects -->
  <xsl:template match="fo:character|fo:inline|fo:inline-container">
    <xsl:call-template name="copy"/>
  </xsl:template>

  <xsl:template match="fo:external-graphic|fo:instream-foreign-object">
    <xsl:call-template name="copy"/>
  </xsl:template>

  <xsl:template match="fo:page-number|fo:page-number-citation|fo:page-number-citation-last">
    <xsl:call-template name="copy"/>
  </xsl:template>

  <!-- Formatting Objects for Tables -->
  <xsl:template match="fo:table-and-caption|fo:table-caption">
    <xsl:call-template name="copy"/>
  </xsl:template>

  <xsl:template match="fo:table|fo:table-header|fo:table-footer|fo:table-body|fo:table-row">
    <xsl:call-template name="copy"/>
  </xsl:template>

  <xsl:template name="get.column.header">
    <xsl:value-of select="ancestor::fo:table/fo:table-column[
      count(preceding-sibling::fo:table-column) = count(current()/preceding-sibling::fo:table-cell)]/@fox:header"/>
  </xsl:template>

  <xsl:template match="fo:table-cell">
    <xsl:variable name="header"><xsl:call-template name="get.column.header"/></xsl:variable>
    <xsl:copy>
      <xsl:if test="$header = 'true'">
        <xsl:attribute name="role">TH</xsl:attribute>
        <xsl:attribute name="scope" namespace="http://xmlgraphics.apache.org/fop/internal">Row</xsl:attribute>
      </xsl:if>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="fo:table-header/fo:table-cell|fo:table-header/fo:table-row/fo:table-cell">
    <xsl:variable name="header"><xsl:call-template name="get.column.header"/></xsl:variable>
    <xsl:copy>
      <xsl:attribute name="role">TH</xsl:attribute>
      <xsl:if test="$header = 'true'">
        <xsl:attribute name="scope" namespace="http://xmlgraphics.apache.org/fop/internal">Both</xsl:attribute>
      </xsl:if>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <!-- Formatting Objects for Lists -->
  <xsl:template match="fo:list-block|fo:list-item|fo:list-item-label|fo:list-item-body">
    <xsl:call-template name="copy"/>
  </xsl:template>

  <!-- Dynamic Effects: Link and Multi Formatting Objects -->
  <xsl:template match="fo:basic-link">
    <xsl:call-template name="copy"/>
  </xsl:template>

  <!-- Out-of-Line Formatting Objects -->
  <xsl:template match="fo:float|fo:footnote|fo:footnote-body">
    <xsl:call-template name="copy"/>
  </xsl:template>

  <!-- Other Formatting Objects -->
  <xsl:template match="fo:wrapper|fo:marker">
    <xsl:call-template name="copy"/>
  </xsl:template>

  <xsl:template match="fo:wrapper[translate(normalize-space(@role), 'ARTIFCT', 'artifct') = 'artifact']"/>


  <!-- Discard descendants of fo:leader -->
  <xsl:template match="fo:leader"/>


  <!-- Keep fox:alt-text and role attributes, discard everything else -->
  <xsl:template match="@fox:alt-text|@role">
    <xsl:copy-of select="."/>
  </xsl:template>

  <xsl:template match="@*"/>


  <!-- Discard text nodes... -->
  <xsl:template match="text()"/>

  <!-- ...except those that will result into marked content -->
  <xsl:template match="fo:title/text()
    |fo:block/text()
    |fo:bidi-override/text()
    |fo:inline/text()
    |fo:basic-link/text()
    |fo:wrapper/text()
    |fo:marker/text()">
    <marked-content xmlns="http://xmlgraphics.apache.org/fop/intermediate"/>
  </xsl:template>

</xsl:stylesheet>