annotate summa/bilingual/merge.xsl @ 67:734a1915d5e2

missed h4 in fallback case
author ht
date Sun, 03 Jan 2010 18:46:03 +0000
parents 036ea6d3e18b
children f34d539f9b78
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
1 <?xml version='1.0'?>
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
2 <!DOCTYPE doc SYSTEM "../../../../lib/xml/xsl.dtd" >
54
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
3 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" exclude-result-prefixes="x" xmlns:x="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml">
42
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
4
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
5 <!-- Merge wrapped latin and prepped english to produce two-column
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
6 bilingual for a single Summa Question -->
65
036ea6d3e18b switch to list of latin files
ht
parents: 61
diff changeset
7 <xsl:param name="lfs">xyzzy</xsl:param><!-- names of latin files -->
036ea6d3e18b switch to list of latin files
ht
parents: 61
diff changeset
8 <xsl:variable name="latin" select="for $lf in tokenize($lfs,';') return document($lf,/)/*"/>
42
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
9 <xsl:key name="lq" match="x:div[@class='q']" use="@id"/>
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
10 <xsl:variable name="di" select="/x:div/@id"/>
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
11 <xsl:variable name="qi" select="concat('q',substring-after($di,'_Q'))"/>
65
036ea6d3e18b switch to list of latin files
ht
parents: 61
diff changeset
12 <xsl:variable name="la" select="for $ld in $latin return key('lq',$qi,$ld)"/>
42
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
13
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
14 <xsl:template match="node()|@*">
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
15 <xsl:copy>
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
16 <xsl:apply-templates select="node()|@*"/>
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
17 </xsl:copy>
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
18 </xsl:template>
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
19
54
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
20 <xsl:template match="x:div[@class='div4' and not(@id)]">
44
d16e7ecf99ad add prooemium
ht
parents: 43
diff changeset
21 <!-- Wrap a prooemium -->
d16e7ecf99ad add prooemium
ht
parents: 43
diff changeset
22 <xsl:copy>
54
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
23 <xsl:call-template name="doBi">
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
24 <xsl:with-param select="@*|node()" name="english"/>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
25 <xsl:with-param select="$la/x:div[@class='p']/x:p" name="latin"/>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
26 </xsl:call-template>
44
d16e7ecf99ad add prooemium
ht
parents: 43
diff changeset
27 </xsl:copy>
d16e7ecf99ad add prooemium
ht
parents: 43
diff changeset
28 </xsl:template>
d16e7ecf99ad add prooemium
ht
parents: 43
diff changeset
29
54
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
30 <xsl:template match="x:div[@class='div4' and @id]">
42
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
31 <!-- Wraps a single article within a question -->
54
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
32 <xsl:variable name="n" select="count(preceding-sibling::x:div[@id])+1"/>
42
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
33 <xsl:variable name="ld" select="$la/x:div[@class='a'][position()=$n]"/>
61
bfebbcb9ddf1 allow for multi-para s.c. div in latin
ht
parents: 54
diff changeset
34 <xsl:variable name="lp" select="$ld/*[self::x:p or self::x:div]"/>
bfebbcb9ddf1 allow for multi-para s.c. div in latin
ht
parents: 54
diff changeset
35 <xsl:message><xsl:value-of select="@id"/>,<xsl:value-of select="$n"/>,<xsl:value-of select="x:h4"/>,<xsl:value-of select="count(x:p)"/>,<xsl:value-of select="$ld/x:h3"/>,<xsl:value-of select="count($lp)"/></xsl:message>
43
d49f2ca9374c all but proemium working
ht
parents: 42
diff changeset
36 <xsl:choose>
61
bfebbcb9ddf1 allow for multi-para s.c. div in latin
ht
parents: 54
diff changeset
37 <xsl:when test="count(x:p)=count($lp)">
43
d49f2ca9374c all but proemium working
ht
parents: 42
diff changeset
38 <xsl:copy>
d49f2ca9374c all but proemium working
ht
parents: 42
diff changeset
39 <xsl:apply-templates select="@*|x:h4"/>
54
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
40 <xsl:for-each select="x:p">
43
d49f2ca9374c all but proemium working
ht
parents: 42
diff changeset
41 <xsl:variable name="i" select="position()"/>
54
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
42 <xsl:call-template name="doBi">
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
43 <xsl:with-param select="." name="english"/>
61
bfebbcb9ddf1 allow for multi-para s.c. div in latin
ht
parents: 54
diff changeset
44 <xsl:with-param select="$lp[position()=$i]" name="latin"/>
54
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
45 </xsl:call-template>
43
d49f2ca9374c all but proemium working
ht
parents: 42
diff changeset
46 </xsl:for-each>
d49f2ca9374c all but proemium working
ht
parents: 42
diff changeset
47 </xsl:copy>
d49f2ca9374c all but proemium working
ht
parents: 42
diff changeset
48 </xsl:when>
d49f2ca9374c all but proemium working
ht
parents: 42
diff changeset
49 <xsl:otherwise>
61
bfebbcb9ddf1 allow for multi-para s.c. div in latin
ht
parents: 54
diff changeset
50 <xsl:message>Can't merge article <xsl:value-of select="@id"/>, <xsl:value-of select="count(x:p)"/>!=<xsl:value-of select="count($lp)"/></xsl:message>
54
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
51 <!-- Try to split on keywords in English -->
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
52 <xsl:variable name="pb" select="count(x:p/x:b[starts-with(.,'Objection') or (.='On the contrary,') or (.='I answer that,') or starts-with(.,'Reply to ')])"/>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
53 <xsl:choose>
61
bfebbcb9ddf1 allow for multi-para s.c. div in latin
ht
parents: 54
diff changeset
54 <xsl:when test="$pb=count($lp)">
67
734a1915d5e2 missed h4 in fallback case
ht
parents: 65
diff changeset
55 <xsl:copy>
734a1915d5e2 missed h4 in fallback case
ht
parents: 65
diff changeset
56 <xsl:apply-templates select="@*|x:h4"/>
734a1915d5e2 missed h4 in fallback case
ht
parents: 65
diff changeset
57 <xsl:for-each-group select="x:p" group-starting-with="x:p[x:b[starts-with(.,'Objection') or (.='On the contrary,') or (.='I answer that,') or starts-with(.,'Reply to ')]]">
54
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
58 <xsl:variable name="i" select="position()"/>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
59 <xsl:call-template name="doBi">
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
60 <xsl:with-param select="current-group()" name="english"/>
61
bfebbcb9ddf1 allow for multi-para s.c. div in latin
ht
parents: 54
diff changeset
61 <xsl:with-param select="$lp[position()=$i]" name="latin"/>
54
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
62 </xsl:call-template>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
63 </xsl:for-each-group>
67
734a1915d5e2 missed h4 in fallback case
ht
parents: 65
diff changeset
64 </xsl:copy>
54
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
65 </xsl:when>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
66 <xsl:otherwise>
61
bfebbcb9ddf1 allow for multi-para s.c. div in latin
ht
parents: 54
diff changeset
67 <xsl:message>Still can't merge article <xsl:value-of select="@id"/>, <xsl:value-of select="$pb"/>!=<xsl:value-of select="count($lp)"/></xsl:message>
54
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
68 </xsl:otherwise>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
69 </xsl:choose>
43
d49f2ca9374c all but proemium working
ht
parents: 42
diff changeset
70 </xsl:otherwise>
d49f2ca9374c all but proemium working
ht
parents: 42
diff changeset
71 </xsl:choose>
42
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
72 </xsl:template>
54
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
73
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
74 <xsl:template name="doBi">
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
75 <xsl:param name="english"/>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
76 <xsl:param name="latin"/>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
77 <div class="bilingual">
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
78 <xsl:choose>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
79 <xsl:when test="count($english)=1">
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
80 <xsl:for-each select="$english">
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
81 <xsl:copy>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
82 <xsl:attribute name="class">english</xsl:attribute>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
83 <xsl:apply-templates select="@*[not(local-name()='class')]|node()"/>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
84 </xsl:copy>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
85 </xsl:for-each>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
86 </xsl:when>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
87 <xsl:otherwise>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
88 <div class="english">
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
89 <xsl:apply-templates select="$english"/>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
90 </div>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
91 </xsl:otherwise>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
92 </xsl:choose>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
93 <xsl:for-each select="$latin">
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
94 <xsl:copy>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
95 <xsl:attribute name="class">latin</xsl:attribute>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
96 <xsl:apply-templates select="@*[not(local-name()='class')]|node()"/>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
97 </xsl:copy>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
98 </xsl:for-each>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
99 </div>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
100 </xsl:template>
42
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
101 </xsl:stylesheet>