Statistics
| Revision:

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

History | View | Annotate | Download (6.4 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://purl.oclc.org/dsdl/schematron"
7
                xmlns="http://purl.oclc.org/dsdl/schematron"
8
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
9
                version="2.0"
10
                exclude-result-prefixes="tei rng teix sch xi
11
					 #default">
12

    
13
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
14
    <desc>
15
      <p> TEI stylesheet for simplifying TEI ODD markup </p>
16
      <p>This software is dual-licensed:
17

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

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

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

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

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

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

    
54
  <xsl:output encoding="utf-8" indent="yes" method="xml"/>
55
  <xsl:param name="lang"></xsl:param>
56
  <xsl:key name="NS" 
57
	   match="sch:ns"
58
	   use="1"/>
59

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

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

    
68

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

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

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