Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / macro / oriflamms / prepare / oriflamms-addxmlid.xsl @ 479

History | View | Annotate | Download (3.2 kB)

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">
6

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

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

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

    
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">
41
        <xsl:choose>
42
          <xsl:when test="$elementname='milestone' and @unit='surface'">
43
            <xsl:value-of select="concat('surf_',$filename,'_',substring-before(@facs,'.'))"/>
44
          </xsl:when>
45
          <xsl:when test="$elementname='pb'">
46
            <xsl:value-of select="concat('page_',$filename,'_',$number)"/>
47
          </xsl:when>
48
          <xsl:when test="$elementname='cb'">
49
            <xsl:value-of select="concat('col_',$filename,'_',$number)"/>
50
          </xsl:when>
51
          <xsl:when test="$elementname='lb'">
52
            <xsl:value-of select="concat('line_',$filename,'_',$number)"/>
53
          </xsl:when>
54
          <xsl:when test="$elementname='seg' and @type='wp'">
55
            <xsl:value-of select="concat('wp_',$filename,'_',$number)"/>
56
          </xsl:when>
57
          <xsl:otherwise>
58
            <xsl:value-of select="concat($elementname,'_',$filename,'_',$number)"/>
59
          </xsl:otherwise>
60
        </xsl:choose>
61
      </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">
68
<!--        <xsl:choose>
69
          <xsl:when test="@n">
70
            <xsl:value-of select="concat('#line_',$filename,'_',@n)"/>
71
          </xsl:when>
72
          <xsl:otherwise>
73
            <xsl:value-of select="concat('#line_',$filename,'_',$number + 1)"/>
74
          </xsl:otherwise>
75
        </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>
83

    
84

    
85

    
86
</xsl:stylesheet>