-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_error_markup.xsl
67 lines (57 loc) · 1.74 KB
/
add_error_markup.xsl
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
<?xml version="1.0" encoding="UTF-8"?>
<!--+
| add_error_markup.xsl
|
| This stylesheet uses XSLT 2 regex and grouping features + recursion to
| convert the ()$€£¥() error markup to xsl elements.
+-->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:strip-space elements="*"/>
<xsl:output method="xml"
version="1.0"
encoding="UTF-8"
indent="yes"/>
<!-- Match all paragraphs containing error markup: -->
<xsl:template match="p[matches(.,'[€$£¥]')]">
<p>
<!--xsl:choose>
<xsl:when test="em | hyph | span"> < ! - - Possible content of a converted doc- - >
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose-->
<xsl:variable name="text" select="."/>
<xsl:call-template name="add-markup">
<xsl:with-param name="text" select="."/>
</xsl:call-template>
</p>
</xsl:template>
<xsl:template name="add-markup">
<xsl:param name="text" />
<xsl:analyze-string select="$text"
regex="(.* )(\w+)$(\w+)( .*)">
<xsl:matching-substring>
<xsl:value-of select="regex-group(1)"/>
<errorort>
<xsl:attribute name="correct">
<xsl:value-of select="regex-group(3)"/>
</xsl:attribute>
<xsl:value-of select="regex-group(2)"/>
</errorort>
<xsl:value-of select="regex-group(4)"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
NO MATCHES!!!
<xsl:value-of select="$text"/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
<!-- Copy everything else -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>