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

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

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

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

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

  
19
<xsl:param name="elements">w|lb|cb|pb|pc|milestone|seg</xsl:param>
20
  
21
  <xsl:variable name="elementsregex"><xsl:value-of select="concat('^(',$elements,')$')"/></xsl:variable>
22
  
23
  <xsl:variable name="filename">
24
    <xsl:analyze-string select="document-uri(.)" regex="^(.*)/([^/]+)$">
25
      <xsl:matching-substring>
26
        <xsl:value-of select="replace(regex-group(2),'(-ori)?(-wp?)?\.[^.]+$','')"/>
27
      </xsl:matching-substring>
28
    </xsl:analyze-string></xsl:variable>
29
  
30
  
31
<xsl:template match="*[matches(local-name(),$elementsregex)]">
32
  <xsl:variable name="elementname">
33
    <xsl:value-of select="local-name()"></xsl:value-of>
34
  </xsl:variable>
35
  <xsl:variable name="number" as="xs:integer">
36
    <xsl:number level="any"/>
37
  </xsl:variable>
38
  <xsl:copy>
39
    <xsl:if test="not(@xml:id)">
40
      <xsl:attribute name="xml:id">
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">
41 54
        <xsl:choose>
42
          <xsl:when test="$elementname='milestone' and @unit='surface'">
43
            <xsl:value-of select="concat('surf_',$filename,'_',substring-before(@facs,'.'))"/>
55
          <xsl:when
56
					test="$elementname='milestone' and @unit='surface'">
57
            <xsl:value-of
58
					select="concat('surf_',$filename,'_',substring-before(@facs,'.'))" />
44 59
          </xsl:when>
45 60
          <xsl:when test="$elementname='pb'">
46
            <xsl:value-of select="concat('page_',$filename,'_',$number)"/>
61
            <xsl:value-of
62
					select="concat('page_',$filename,'_',$number)" />
47 63
          </xsl:when>
48 64
          <xsl:when test="$elementname='cb'">
49
            <xsl:value-of select="concat('col_',$filename,'_',$number)"/>
65
            <xsl:value-of
66
					select="concat('col_',$filename,'_',$number)" />
50 67
          </xsl:when>
51 68
          <xsl:when test="$elementname='lb'">
52
            <xsl:value-of select="concat('line_',$filename,'_',$number)"/>
69
            <xsl:value-of
70
					select="concat('line_',$filename,'_',$number)" />
53 71
          </xsl:when>
54 72
          <xsl:when test="$elementname='seg' and @type='wp'">
55
            <xsl:value-of select="concat('wp_',$filename,'_',$number)"/>
73
            <xsl:value-of
74
					select="concat('wp_',$filename,'_',$number)" />
56 75
          </xsl:when>
57 76
          <xsl:otherwise>
58
            <xsl:value-of select="concat($elementname,'_',$filename,'_',$number)"/>
77
            <xsl:value-of
78
					select="concat($elementname,'_',$filename,'_',$number)" />
59 79
          </xsl:otherwise>
60 80
        </xsl:choose>
61 81
      </xsl:attribute>
62
    </xsl:if>
63
    <xsl:if test="not(@n) and not(matches($elementname,'^(w|pc|seg)$'))">
64
      <xsl:attribute name="n"><xsl:value-of select="$number"/></xsl:attribute>
65
    </xsl:if>
66
    <xsl:if test="$elementname='lb' and @type='rejet' and not(@corresp)">
67
      <xsl:attribute name="corresp">
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">
68 91
<!--        <xsl:choose>
69 92
          <xsl:when test="@n">
70 93
            <xsl:value-of select="concat('#line_',$filename,'_',@n)"/>
......
73 96
            <xsl:value-of select="concat('#line_',$filename,'_',$number + 1)"/>
74 97
          </xsl:otherwise>
75 98
        </xsl:choose>-->
76
        <xsl:value-of select="concat('#line_',$filename,'_',$number + 1)"/>
77
      </xsl:attribute>      
78
    </xsl:if>
79
    <xsl:apply-templates select="@*"/>
80
    <xsl:apply-templates/>
81
  </xsl:copy>
82
</xsl:template>
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>
83 107

  
84 108

  
85 109

  

Also available in: Unified diff