Statistics
| Revision:

root / tmp / org.txm.core / res / org / txm / xml / xsl / tei / odds2 / extract-sch.xsl @ 187

History | View | Annotate | Download (5.8 kB)

1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet xmlns:teix="http://www.tei-c.org/ns/Examples"
3
                xmlns:xi="http://www.w3.org/2001/XInclude"
4
                xmlns:rng="http://relaxng.org/ns/structure/1.0"
5
                xmlns:tei="http://www.tei-c.org/ns/1.0"
6
		xmlns:sch="http://www.ascc.net/xml/schematron"
7
		xmlns="http://www.ascc.net/xml/schematron"
8
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
9
                version="2.0"
10
                exclude-result-prefixes="tei rng teix sch xi #default">
11
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
12
    <desc>
13
      <p> TEI stylesheet for simplifying TEI ODD markup </p>
14
      <p>This software is dual-licensed:
15

    
16
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
17
Unported License http://creativecommons.org/licenses/by-sa/3.0/ 
18

    
19
2. http://www.opensource.org/licenses/BSD-2-Clause
20
		
21
All rights reserved.
22

    
23
Redistribution and use in source and binary forms, with or without
24
modification, are permitted provided that the following conditions are
25
met:
26

    
27
* Redistributions of source code must retain the above copyright
28
notice, this list of conditions and the following disclaimer.
29

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

    
34
This software is provided by the copyright holders and contributors
35
"as is" and any express or implied warranties, including, but not
36
limited to, the implied warranties of merchantability and fitness for
37
a particular purpose are disclaimed. In no event shall the copyright
38
holder or contributors be liable for any direct, indirect, incidental,
39
special, exemplary, or consequential damages (including, but not
40
limited to, procurement of substitute goods or services; loss of use,
41
data, or profits; or business interruption) however caused and on any
42
theory of liability, whether in contract, strict liability, or tort
43
(including negligence or otherwise) arising in any way out of the use
44
of this software, even if advised of the possibility of such damage.
45
</p>
46
      <p>Author: See AUTHORS</p>
47
      <p>Id: $Id: extract-sch.xsl 9646 2011-11-05 23:39:08Z rahtz $</p>
48
      <p>Copyright: 2011, TEI Consortium</p>
49
    </desc>
50
  </doc>
51
  <xsl:output encoding="utf-8" indent="yes" method="xml"/>
52
  <xsl:param name="lang"></xsl:param>
53

    
54
  <xsl:key name="NS" 
55
	   match="sch:ns"
56
	   use="1"/>
57

    
58
  <xsl:key name="PATTERNS"
59
	   match="sch:pattern"
60
	   use="1"/>
61

    
62
  <xsl:key name="CONSTRAINTS"
63
	   match="tei:constraint"
64
	   use="1"/>
65

    
66

    
67
  <xsl:template match="/">
68
      <schema>
69
         <title>Schematron 1.5 rules</title>
70
         <xsl:for-each select="key('NS',1)">
71
            <xsl:choose>
72
               <xsl:when test="ancestor::teix:egXML"/>
73
	       <xsl:when test="ancestor::tei:constraintSpec/@xml:lang
74
		 and not(ancestor::tei:constraintSpec/@xml:lang = $lang)"/>
75
               <xsl:otherwise>
76
                  <xsl:apply-templates select="."/>
77
               </xsl:otherwise>
78
            </xsl:choose>
79
         </xsl:for-each>
80

    
81
         <xsl:for-each select="key('PATTERNS',1)">
82
            <xsl:choose>
83
               <xsl:when test="ancestor::teix:egXML"/>
84
	       <xsl:when test="ancestor::tei:constraintSpec/@xml:lang
85
		 and not(ancestor::tei:constraintSpec/@xml:lang = $lang)"/>
86
               <xsl:otherwise>
87
                  <xsl:apply-templates select="."/>
88
               </xsl:otherwise>
89
            </xsl:choose>
90
         </xsl:for-each>
91

    
92
         <xsl:for-each select="key('CONSTRAINTS',1)">
93
            <xsl:choose>
94
               <xsl:when test="ancestor::teix:egXML"/>
95
	       <xsl:when test="ancestor::tei:constraintSpec/@xml:lang
96
		 and not(ancestor::tei:constraintSpec/@xml:lang = $lang)"/>
97
               <xsl:otherwise>
98
		 <xsl:variable name="patID">
99
		   <xsl:choose>
100
		     <xsl:when test="ancestor::tei:elementSpec">
101
		       <xsl:value-of select="concat(ancestor::tei:elementSpec/@ident,'-constraint-',ancestor::tei:constraintSpec/@ident)"/>
102
		     </xsl:when>
103
		     <xsl:when test="ancestor::tei:classSpec">
104
		       <xsl:value-of select="concat(ancestor::tei:classSpec/@ident,'-constraint-',ancestor::tei:constraintSpec/@ident)"/>
105
		     </xsl:when>
106
		     <xsl:when test="ancestor::tei:macroSpec">
107
		       <xsl:value-of select="concat(ancestor::tei:macroSpec/@ident,'-constraint-',ancestor::tei:constraintSpec/@ident)"/>
108
		     </xsl:when>
109
                     </xsl:choose>
110
                  </xsl:variable>
111
		 <xsl:if test="sch:rule">
112
		   <pattern id="{$patID}">
113
		     <xsl:apply-templates select="sch:rule"/>
114
		   </pattern>
115
		 </xsl:if>
116
		 <xsl:if test="sch:assert|sch:report">
117
		   <pattern id="{$patID}">
118
		     <rule>
119
		       <xsl:attribute name="context">
120
			 <xsl:text>tei:</xsl:text>
121
			 <xsl:choose>
122
			   <xsl:when test="ancestor::tei:elementSpec">
123
			     <xsl:value-of
124
				 select="ancestor::tei:elementSpec/@ident"/>
125
			   </xsl:when>
126
			   <xsl:otherwise>*</xsl:otherwise>
127
			 </xsl:choose>
128
		       </xsl:attribute>
129
		       <xsl:apply-templates select="sch:assert|sch:report"/>
130
		     </rule>
131
		   </pattern>
132
		 </xsl:if>
133
               </xsl:otherwise>
134
            </xsl:choose>
135
         </xsl:for-each>
136
      </schema>
137
  </xsl:template>
138
  
139
  <xsl:template match="sch:rule[not(@context)]">
140
    <rule>
141
      <xsl:attribute name="context">
142
	<xsl:text>tei:</xsl:text>
143
	<xsl:value-of select="ancestor::tei:elementSpec/@ident"/>
144
      </xsl:attribute>
145
      <xsl:apply-templates/>
146
    </rule>
147
  </xsl:template>
148
  
149
  
150
  <xsl:template match="@*|text()|comment()|processing-instruction()">
151
      <xsl:copy-of select="."/>
152
  </xsl:template>
153
  
154
  
155
  <xsl:template match="sch:*">
156
    <xsl:element name="{local-name()}">
157
      <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()"/>
158
    </xsl:element>
159
  </xsl:template>
160
  
161
</xsl:stylesheet>