annotate summa/bilingual/merge.xsl @ 54:77921d86a058

towards new format, pipeline
author ht
date Tue, 29 Dec 2009 18:40:48 +0000
parents d16e7ecf99ad
children bfebbcb9ddf1
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 -->
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
7 <xsl:param name="lf">xyzzy</xsl:param>
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
8 <xsl:variable name="latin" select="document($lf,/)/*"/>
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'))"/>
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
12 <xsl:variable name="la" select="key('lq',$qi,$latin)"/>
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]"/>
54
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
34 <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($ld/x:p)"/></xsl:message>
43
d49f2ca9374c all but proemium working
ht
parents: 42
diff changeset
35 <xsl:choose>
54
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
36 <xsl:when test="count(x:p)=count($ld/x:p)">
43
d49f2ca9374c all but proemium working
ht
parents: 42
diff changeset
37 <xsl:copy>
d49f2ca9374c all but proemium working
ht
parents: 42
diff changeset
38 <xsl:apply-templates select="@*|x:h4"/>
54
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
39 <xsl:for-each select="x:p">
43
d49f2ca9374c all but proemium working
ht
parents: 42
diff changeset
40 <xsl:variable name="i" select="position()"/>
54
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
41 <xsl:call-template name="doBi">
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
42 <xsl:with-param select="." name="english"/>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
43 <xsl:with-param select="$ld/x:p[position()=$i]" name="latin"/>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
44 </xsl:call-template>
43
d49f2ca9374c all but proemium working
ht
parents: 42
diff changeset
45 </xsl:for-each>
d49f2ca9374c all but proemium working
ht
parents: 42
diff changeset
46 </xsl:copy>
d49f2ca9374c all but proemium working
ht
parents: 42
diff changeset
47 </xsl:when>
d49f2ca9374c all but proemium working
ht
parents: 42
diff changeset
48 <xsl:otherwise>
54
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
49 <xsl:message>Can't merge article <xsl:value-of select="@id"/>, <xsl:value-of select="count(x:p)"/>!=<xsl:value-of select="count($ld/x:p)"/></xsl:message>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
50 <!-- Try to split on keywords in English -->
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
51 <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
52 <xsl:choose>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
53 <xsl:when test="$pb=count($ld/x:p)">
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
54 <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 ')]]">
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
55 <xsl:variable name="i" select="position()"/>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
56 <xsl:call-template name="doBi">
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
57 <xsl:with-param select="current-group()" name="english"/>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
58 <xsl:with-param select="$ld/x:p[position()=$i]" name="latin"/>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
59 </xsl:call-template>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
60 </xsl:for-each-group>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
61 </xsl:when>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
62 <xsl:otherwise>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
63 <xsl:message>Still can't merge article <xsl:value-of select="@id"/>, <xsl:value-of select="$pb"/>!=<xsl:value-of select="count($ld/x:p)"/></xsl:message>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
64 </xsl:otherwise>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
65 </xsl:choose>
43
d49f2ca9374c all but proemium working
ht
parents: 42
diff changeset
66 </xsl:otherwise>
d49f2ca9374c all but proemium working
ht
parents: 42
diff changeset
67 </xsl:choose>
42
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
68 </xsl:template>
54
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
69
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
70 <xsl:template name="doBi">
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
71 <xsl:param name="english"/>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
72 <xsl:param name="latin"/>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
73 <div class="bilingual">
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
74 <xsl:choose>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
75 <xsl:when test="count($english)=1">
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
76 <xsl:for-each select="$english">
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
77 <xsl:copy>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
78 <xsl:attribute name="class">english</xsl:attribute>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
79 <xsl:apply-templates select="@*[not(local-name()='class')]|node()"/>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
80 </xsl:copy>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
81 </xsl:for-each>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
82 </xsl:when>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
83 <xsl:otherwise>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
84 <div class="english">
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
85 <xsl:apply-templates select="$english"/>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
86 </div>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
87 </xsl:otherwise>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
88 </xsl:choose>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
89 <xsl:for-each select="$latin">
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
90 <xsl:copy>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
91 <xsl:attribute name="class">latin</xsl:attribute>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
92 <xsl:apply-templates select="@*[not(local-name()='class')]|node()"/>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
93 </xsl:copy>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
94 </xsl:for-each>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
95 </div>
77921d86a058 towards new format, pipeline
ht
parents: 44
diff changeset
96 </xsl:template>
42
8f4be7dfda7a ready to try real work
ht
parents:
diff changeset
97 </xsl:stylesheet>