|
42
|
1 <?xml version='1.0'?>
|
|
|
2 <!DOCTYPE doc SYSTEM "../../../../lib/xml/xsl.dtd" >
|
|
54
|
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
|
4
|
|
|
5 <!-- Merge wrapped latin and prepped english to produce two-column
|
|
|
6 bilingual for a single Summa Question -->
|
|
|
7 <xsl:param name="lf">xyzzy</xsl:param>
|
|
|
8 <xsl:variable name="latin" select="document($lf,/)/*"/>
|
|
|
9 <xsl:key name="lq" match="x:div[@class='q']" use="@id"/>
|
|
|
10 <xsl:variable name="di" select="/x:div/@id"/>
|
|
|
11 <xsl:variable name="qi" select="concat('q',substring-after($di,'_Q'))"/>
|
|
|
12 <xsl:variable name="la" select="key('lq',$qi,$latin)"/>
|
|
|
13
|
|
|
14 <xsl:template match="node()|@*">
|
|
|
15 <xsl:copy>
|
|
|
16 <xsl:apply-templates select="node()|@*"/>
|
|
|
17 </xsl:copy>
|
|
|
18 </xsl:template>
|
|
|
19
|
|
54
|
20 <xsl:template match="x:div[@class='div4' and not(@id)]">
|
|
44
|
21 <!-- Wrap a prooemium -->
|
|
|
22 <xsl:copy>
|
|
54
|
23 <xsl:call-template name="doBi">
|
|
|
24 <xsl:with-param select="@*|node()" name="english"/>
|
|
|
25 <xsl:with-param select="$la/x:div[@class='p']/x:p" name="latin"/>
|
|
|
26 </xsl:call-template>
|
|
44
|
27 </xsl:copy>
|
|
|
28 </xsl:template>
|
|
|
29
|
|
54
|
30 <xsl:template match="x:div[@class='div4' and @id]">
|
|
42
|
31 <!-- Wraps a single article within a question -->
|
|
54
|
32 <xsl:variable name="n" select="count(preceding-sibling::x:div[@id])+1"/>
|
|
42
|
33 <xsl:variable name="ld" select="$la/x:div[@class='a'][position()=$n]"/>
|
|
54
|
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
|
35 <xsl:choose>
|
|
54
|
36 <xsl:when test="count(x:p)=count($ld/x:p)">
|
|
43
|
37 <xsl:copy>
|
|
|
38 <xsl:apply-templates select="@*|x:h4"/>
|
|
54
|
39 <xsl:for-each select="x:p">
|
|
43
|
40 <xsl:variable name="i" select="position()"/>
|
|
54
|
41 <xsl:call-template name="doBi">
|
|
|
42 <xsl:with-param select="." name="english"/>
|
|
|
43 <xsl:with-param select="$ld/x:p[position()=$i]" name="latin"/>
|
|
|
44 </xsl:call-template>
|
|
43
|
45 </xsl:for-each>
|
|
|
46 </xsl:copy>
|
|
|
47 </xsl:when>
|
|
|
48 <xsl:otherwise>
|
|
54
|
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>
|
|
|
50 <!-- Try to split on keywords in English -->
|
|
|
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 ')])"/>
|
|
|
52 <xsl:choose>
|
|
|
53 <xsl:when test="$pb=count($ld/x:p)">
|
|
|
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 ')]]">
|
|
|
55 <xsl:variable name="i" select="position()"/>
|
|
|
56 <xsl:call-template name="doBi">
|
|
|
57 <xsl:with-param select="current-group()" name="english"/>
|
|
|
58 <xsl:with-param select="$ld/x:p[position()=$i]" name="latin"/>
|
|
|
59 </xsl:call-template>
|
|
|
60 </xsl:for-each-group>
|
|
|
61 </xsl:when>
|
|
|
62 <xsl:otherwise>
|
|
|
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>
|
|
|
64 </xsl:otherwise>
|
|
|
65 </xsl:choose>
|
|
43
|
66 </xsl:otherwise>
|
|
|
67 </xsl:choose>
|
|
42
|
68 </xsl:template>
|
|
54
|
69
|
|
|
70 <xsl:template name="doBi">
|
|
|
71 <xsl:param name="english"/>
|
|
|
72 <xsl:param name="latin"/>
|
|
|
73 <div class="bilingual">
|
|
|
74 <xsl:choose>
|
|
|
75 <xsl:when test="count($english)=1">
|
|
|
76 <xsl:for-each select="$english">
|
|
|
77 <xsl:copy>
|
|
|
78 <xsl:attribute name="class">english</xsl:attribute>
|
|
|
79 <xsl:apply-templates select="@*[not(local-name()='class')]|node()"/>
|
|
|
80 </xsl:copy>
|
|
|
81 </xsl:for-each>
|
|
|
82 </xsl:when>
|
|
|
83 <xsl:otherwise>
|
|
|
84 <div class="english">
|
|
|
85 <xsl:apply-templates select="$english"/>
|
|
|
86 </div>
|
|
|
87 </xsl:otherwise>
|
|
|
88 </xsl:choose>
|
|
|
89 <xsl:for-each select="$latin">
|
|
|
90 <xsl:copy>
|
|
|
91 <xsl:attribute name="class">latin</xsl:attribute>
|
|
|
92 <xsl:apply-templates select="@*[not(local-name()='class')]|node()"/>
|
|
|
93 </xsl:copy>
|
|
|
94 </xsl:for-each>
|
|
|
95 </div>
|
|
|
96 </xsl:template>
|
|
42
|
97 </xsl:stylesheet>
|