-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmettrePdansDiv.xsl
More file actions
108 lines (96 loc) · 4.3 KB
/
mettrePdansDiv.xsl
File metadata and controls
108 lines (96 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?xml version="1.0" encoding="UTF-8"?>
<!-- xpath-default-namespace slmt en XSLT2.0 -->
<!--
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@Name : mettrePdansDiv.xsl
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@version : 005
@creaDate : 2014/05/16
@modifDate
@vXslt: 2.0
@autor : Emmanuel Château emchateau@laposte.net
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@use : cette feuille de style place les éléments P qui commencent par des chiffres dans un div.
@knownBugs : amusant de constater que créé une hiéarchie dans l'état
@todo :
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@inspired : http://www.ibm.com/developerworks/library/x-addstructurexslt/
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
-->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xpath-default-namespace="http://www.tei-c.org/ns/1.0"
xmlns="http://www.tei-c.org/ns/1.0">
<!-- xpath-default-namespace slmt en XSLT2.0 -->
<xsl:output indent="yes" method="xml" encoding="UTF-8" />
<xsl:variable name="number" select="'^\s*(\d+.?)\s*(.*)$'"/>
<xsl:variable name="secRegex" select="'^\s*(\d+\.\d+)\s*(.*)$'"/>
<xsl:template match="document">
<xsl:variable name="renamed" as="element()*">
<xsl:apply-templates select="*" mode="rename"/>
</xsl:variable>
<document>
<xsl:for-each-group select="$renamed" group-starting-with="chapTitle">
<chapter num="{replace(current-group()[self::chapTitle],number,'$1')}">
<xsl:for-each-group select="current-group()" group-starting-with="secTitle">
<xsl:choose>
<xsl:when test="current-group()[self::secTitle]">
<section num="{replace(current-group()[self::secTitle],$secRegex,'$1')}">
<xsl:apply-templates select="current-group()"/>
</section>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</chapter>
</xsl:for-each-group>
</document>
</xsl:template>
<xsl:template match="p[matches(.,$number)]" mode="rename">
<chapTitle>
<xsl:copy-of select="node()"/>
</chapTitle>
</xsl:template>
<xsl:template match="text()" priority="1">
<xsl:choose>
<xsl:when test="matches(.,$number) and (. is parent::chapTitle/node()[1])">
<xsl:value-of select="replace(.,$number,'$2')"/>
</xsl:when>
<!--<xsl:when test="matches(.,$secRegex) and (. is parent::secTitle/node()[1])">
<xsl:value-of select="replace(.,$secRegex,'$2')"/>
</xsl:when>-->
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Copie à l'identique du fichier (toutes les passes) -->
<xsl:template match="node()" mode="#all">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates mode="#current"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
<!--<xsl:template match="p[matches(.,'^\d')]">
<xsl:analyze-string select="." regex="^(\d+.?\s)((.*\n?)*)">
<xsl:matching-substring>
<div type="number">
<label>
<num>
<xsl:value-of select="regex-group(1)" />
</num>
</label>
<p>
<xsl:value-of select="regex-group(2)" />
</p>
</div>
</xsl:matching-substring>
<xsl:non-matching-substring>
<p rend="prb"><xsl:copy-of select="."></xsl:copy-of></p>
</xsl:non-matching-substring>
<xsl:fallback />
</xsl:analyze-string>
</xsl:template>-->