Revision 2398 tmp/org.txm.oriflamms.rcp/res/oriflamms-project-w-id-2-tei-xml-Fontenay.xsl

oriflamms-project-w-id-2-tei-xml-Fontenay.xsl (revision 2398)
1 1
<!-- The Identity Transformation -->
2
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">
3
  
4
  <xsl:output method="xml" cdata-section-elements="Word"></xsl:output>
5
  
6
  <xsl:param name="words-with-id-file">Fontenay-w-id-table.xml</xsl:param>
7
  
8
  <xsl:variable name="words-with-id" as="element()">
9
    <xsl:copy-of select="document($words-with-id-file)//text"></xsl:copy-of>
10
  </xsl:variable>
11
  
12
  
13
  <!-- Whenever you match any node or any attribute -->
14
  <xsl:template match="node()|@*">
15
    <!-- Copy the current node -->
16
    <xsl:copy>
17
      <!-- Including any attributes it has and any child nodes -->
18
      <xsl:apply-templates select="@*|node()"/>
19
    </xsl:copy>
20
  </xsl:template>
21
  
22
  <xsl:template match="Word">
23
    <xsl:variable name="position" as="xs:integer">
24
      <xsl:value-of select="count(preceding::Word[not(matches(.,'__NOISE__'))]) + 1"/>
25
      <!--<xsl:number count="Word[not(matches(.,'__NOISE__'))]" level="any"/>-->
26
    </xsl:variable>
27
    <xsl:if test="$words-with-id/w[$position]/preceding-sibling::*[1][self::w-add]">
28
      <xsl:comment>Added word: </xsl:comment>
29
      <Word x1="{@x1 - 5}" y1="{@y1 - 5}" x2="{@x1 - 1}" y2="{@y2}" valid="0" imgsig="-" leftcorr="0" rightcorr="0">
30
        <xsl:value-of select="$words-with-id/w[$position]/preceding-sibling::w-add[1]"/>
31
      </Word>      
32
    </xsl:if>
33
    <xsl:choose>
34
      <xsl:when test="matches(.,'__NOISE__')">
35
        <xsl:comment><xsl:copy-of select="."></xsl:copy-of></xsl:comment>
36
      </xsl:when>
37
      <xsl:otherwise>
38
        <xsl:copy>
39
          <xsl:apply-templates select="@*"/>
40
          <xsl:attribute name="id"><xsl:value-of select="$words-with-id/w[$position]/@id"/></xsl:attribute>
41
          <xsl:apply-templates/>
42
          <xsl:if test="not(. = $words-with-id/w[$position])">
43
            <xsl:comment>No match! <xsl:value-of select="$words-with-id//w[$position]/text()"/></xsl:comment>
44
          </xsl:if>
45
        </xsl:copy>
46
      </xsl:otherwise>
47
    </xsl:choose>
48
    
49
  </xsl:template>
2
<xsl:stylesheet version="2.0"
3
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4
	xmlns:xs="http://www.w3.org/2001/XMLSchema">
5

  
6
	<xsl:output method="xml" cdata-section-elements="Word"></xsl:output>
7

  
8
	<xsl:param name="words-with-id-file">
9
		Fontenay-w-id-table.xml
10
	</xsl:param>
11

  
12
	<xsl:variable name="words-with-id" as="element()">
13
		<xsl:copy-of select="document($words-with-id-file)//text"></xsl:copy-of>
14
	</xsl:variable>
15

  
16

  
17
	<!-- Whenever you match any node or any attribute -->
18
	<xsl:template match="node()|@*">
19
		<!-- Copy the current node -->
20
		<xsl:copy>
21
			<!-- Including any attributes it has and any child nodes -->
22
			<xsl:apply-templates select="@*|node()" />
23
		</xsl:copy>
24
	</xsl:template>
25

  
26
	<xsl:template match="Word">
27
		<xsl:variable name="position" as="xs:integer">
28
			<xsl:value-of
29
				select="count(preceding::Word[not(matches(.,'__NOISE__'))]) + 1" />
30
			<!--<xsl:number count="Word[not(matches(.,'__NOISE__'))]" level="any"/> -->
31
		</xsl:variable>
32
		<xsl:if
33
			test="$words-with-id/w[$position]/preceding-sibling::*[1][self::w-add]">
34
			<xsl:comment>
35
				Added word:
36
			</xsl:comment>
37
			<Word x1="{@x1 - 5}" y1="{@y1 - 5}" x2="{@x1 - 1}" y2="{@y2}"
38
				valid="0" imgsig="-" leftcorr="0" rightcorr="0">
39
				<xsl:value-of
40
					select="$words-with-id/w[$position]/preceding-sibling::w-add[1]" />
41
			</Word>
42
		</xsl:if>
43
		<xsl:choose>
44
			<xsl:when test="matches(.,'__NOISE__')">
45
				<xsl:comment>
46
					<xsl:copy-of select="."></xsl:copy-of>
47
				</xsl:comment>
48
			</xsl:when>
49
			<xsl:otherwise>
50
				<xsl:copy>
51
					<xsl:apply-templates select="@*" />
52
					<xsl:attribute name="id"><xsl:value-of
53
						select="$words-with-id/w[$position]/@id" /></xsl:attribute>
54
					<xsl:apply-templates />
55
					<xsl:if test="not(. = $words-with-id/w[$position])">
56
						<xsl:comment>
57
							No match!
58
							<xsl:value-of
59
								select="$words-with-id//w[$position]/text()" />
60
						</xsl:comment>
61
					</xsl:if>
62
				</xsl:copy>
63
			</xsl:otherwise>
64
		</xsl:choose>
65

  
66
	</xsl:template>
50 67
</xsl:stylesheet>

Also available in: Unified diff