Statistics
| Revision:

root / tmp / org.txm.oriflamms.rcp / groovy / org / txm / macro / oriflamms / prepare / oriflamms-addxmlid.xsl @ 2398

History | View | Annotate | Download (3.2 kB)

1
<?xml version="1.0"?>
2
<xsl:stylesheet
3
	xmlns:edate="http://exslt.org/dates-and-times"
4
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5
	xmlns:tei="http://www.tei-c.org/ns/1.0"
6
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
7
	exclude-result-prefixes="tei edate" version="2.0">
8

    
9
	<xsl:output method="xml" encoding="utf-8"
10
		omit-xml-declaration="no" />
11

    
12
	<xsl:template match="*">
13
		<xsl:copy>
14
			<xsl:apply-templates
15
				select="*|@*|processing-instruction()|comment()|text()" />
16
		</xsl:copy>
17
	</xsl:template>
18

    
19
	<xsl:template
20
		match="@*|processing-instruction()|comment()|text()">
21
		<xsl:copy />
22
	</xsl:template>
23

    
24
	<xsl:param name="elements">
25
		w|lb|cb|pb|pc|milestone|seg
26
	</xsl:param>
27

    
28
	<xsl:variable name="elementsregex">
29
		<xsl:value-of select="concat('^(',$elements,')$')" />
30
	</xsl:variable>
31

    
32
	<xsl:variable name="filename">
33
		<xsl:analyze-string select="document-uri(.)"
34
			regex="^(.*)/([^/]+)$">
35
			<xsl:matching-substring>
36
				<xsl:value-of
37
					select="replace(regex-group(2),'(-ori)?(-wp?)?\.[^.]+$','')" />
38
			</xsl:matching-substring>
39
		</xsl:analyze-string>
40
	</xsl:variable>
41

    
42

    
43
	<xsl:template
44
		match="*[matches(local-name(),$elementsregex)]">
45
		<xsl:variable name="elementname">
46
			<xsl:value-of select="local-name()"></xsl:value-of>
47
		</xsl:variable>
48
		<xsl:variable name="number" as="xs:integer">
49
			<xsl:number level="any" />
50
		</xsl:variable>
51
		<xsl:copy>
52
			<xsl:if test="not(@xml:id)">
53
				<xsl:attribute name="xml:id">
54
        <xsl:choose>
55
          <xsl:when
56
					test="$elementname='milestone' and @unit='surface'">
57
            <xsl:value-of
58
					select="concat('surf_',$filename,'_',substring-before(@facs,'.'))" />
59
          </xsl:when>
60
          <xsl:when test="$elementname='pb'">
61
            <xsl:value-of
62
					select="concat('page_',$filename,'_',$number)" />
63
          </xsl:when>
64
          <xsl:when test="$elementname='cb'">
65
            <xsl:value-of
66
					select="concat('col_',$filename,'_',$number)" />
67
          </xsl:when>
68
          <xsl:when test="$elementname='lb'">
69
            <xsl:value-of
70
					select="concat('line_',$filename,'_',$number)" />
71
          </xsl:when>
72
          <xsl:when test="$elementname='seg' and @type='wp'">
73
            <xsl:value-of
74
					select="concat('wp_',$filename,'_',$number)" />
75
          </xsl:when>
76
          <xsl:otherwise>
77
            <xsl:value-of
78
					select="concat($elementname,'_',$filename,'_',$number)" />
79
          </xsl:otherwise>
80
        </xsl:choose>
81
      </xsl:attribute>
82
			</xsl:if>
83
			<xsl:if
84
				test="not(@n) and not(matches($elementname,'^(w|pc|seg)$'))">
85
				<xsl:attribute name="n"><xsl:value-of
86
					select="$number" /></xsl:attribute>
87
			</xsl:if>
88
			<xsl:if
89
				test="$elementname='lb' and @type='rejet' and not(@corresp)">
90
				<xsl:attribute name="corresp">
91
<!--        <xsl:choose>
92
          <xsl:when test="@n">
93
            <xsl:value-of select="concat('#line_',$filename,'_',@n)"/>
94
          </xsl:when>
95
          <xsl:otherwise>
96
            <xsl:value-of select="concat('#line_',$filename,'_',$number + 1)"/>
97
          </xsl:otherwise>
98
        </xsl:choose>-->
99
        <xsl:value-of
100
					select="concat('#line_',$filename,'_',$number + 1)" />
101
      </xsl:attribute>
102
			</xsl:if>
103
			<xsl:apply-templates select="@*" />
104
			<xsl:apply-templates />
105
		</xsl:copy>
106
	</xsl:template>
107

    
108

    
109

    
110
</xsl:stylesheet>