Mercurial > hg > Aquinas
view summa/bilingual/merge.xsl @ 100:eea25317dfad
clarify order of messages
| author | ht |
|---|---|
| date | Fri, 13 Feb 2015 14:54:33 +0000 |
| parents | f34d539f9b78 |
| children | c910f10a8e83 |
line wrap: on
line source
<?xml version='1.0'?> <!DOCTYPE doc SYSTEM "../../../../lib/xml/xsl.dtd" > <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"> <!-- Merge wrapped latin and prepped english to produce two-column bilingual for a single Summa Question --> <xsl:param name="lfs">xyzzy</xsl:param><!-- names of latin files --> <xsl:variable name="latin" select="for $lf in tokenize($lfs,';') return document($lf,/)/*"/> <xsl:key name="lq" match="x:div[@class='q']" use="@id"/> <xsl:variable name="di" select="/x:div/@id"/> <xsl:variable name="qi" select="concat('q',substring-after($di,'_Q'))"/> <xsl:variable name="la" select="for $ld in $latin return key('lq',$qi,$ld)"/> <xsl:template match="/"> <xsl:message> <xsl:text>English|Latin|latin count </xsl:text> <xsl:value-of select="$di"/>|<xsl:value-of select="$qi"/>|<xsl:value-of select="count($la)"/> </xsl:message> <xsl:apply-templates/> </xsl:template> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="x:div[@class='div4' and not(@id)]"> <!-- Wrap a prooemium --> <xsl:copy> <xsl:call-template name="doBi"> <xsl:with-param select="@*|node()" name="english"/> <xsl:with-param select="$la/x:div[@class='p']/x:p" name="latin"/> </xsl:call-template> </xsl:copy> </xsl:template> <xsl:template match="x:div[@class='div4' and @id]"> <!-- Wraps a single article within a question --> <xsl:variable name="n" select="count(preceding-sibling::x:div[@id])+1"/> <xsl:variable name="ld" select="$la/x:div[@class='a'][position()=$n]"/> <xsl:variable name="lp" select="$ld/*[self::x:p or self::x:div]"/> <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> <xsl:choose> <xsl:when test="count(x:p)=count($lp)"> <xsl:copy> <xsl:apply-templates select="@*|x:h4"/> <xsl:for-each select="x:p"> <xsl:variable name="i" select="position()"/> <xsl:call-template name="doBi"> <xsl:with-param select="." name="english"/> <xsl:with-param select="$lp[position()=$i]" name="latin"/> </xsl:call-template> </xsl:for-each> </xsl:copy> </xsl:when> <xsl:otherwise> <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> <!-- Try to split on keywords in English --> <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 ')])"/> <xsl:choose> <xsl:when test="$pb=count($lp)"> <xsl:copy> <xsl:apply-templates select="@*|x:h4"/> <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 ')]]"> <xsl:variable name="i" select="position()"/> <xsl:call-template name="doBi"> <xsl:with-param select="current-group()" name="english"/> <xsl:with-param select="$lp[position()=$i]" name="latin"/> </xsl:call-template> </xsl:for-each-group> </xsl:copy> </xsl:when> <xsl:otherwise> <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> </xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="doBi"> <xsl:param name="english"/> <xsl:param name="latin"/> <div class="bilingual"> <xsl:choose> <xsl:when test="count($english)=1"> <xsl:for-each select="$english"> <xsl:copy> <xsl:attribute name="class">english</xsl:attribute> <xsl:apply-templates select="@*[not(local-name()='class')]|node()"/> </xsl:copy> </xsl:for-each> </xsl:when> <xsl:otherwise> <div class="english"> <xsl:apply-templates select="$english"/> </div> </xsl:otherwise> </xsl:choose> <xsl:for-each select="$latin"> <xsl:copy> <xsl:attribute name="class">latin</xsl:attribute> <xsl:apply-templates select="@*[not(local-name()='class')]|node()"/> </xsl:copy> </xsl:for-each> </div> </xsl:template> </xsl:stylesheet>
