Mercurial > hg > Aquinas
changeset 54:77921d86a058
towards new format, pipeline
| author | ht |
|---|---|
| date | Tue, 29 Dec 2009 18:40:48 +0000 |
| parents | d777cc3962f2 |
| children | 093a560860d9 |
| files | summa/bilingual/fixup_e.xsl summa/bilingual/merge.xpl summa/bilingual/merge.xsl |
| diffstat | 3 files changed, 88 insertions(+), 69 deletions(-) [+] |
line wrap: on
line diff
--- a/summa/bilingual/fixup_e.xsl Mon Dec 28 13:00:58 2009 +0000 +++ b/summa/bilingual/fixup_e.xsl Tue Dec 29 18:40:48 2009 +0000 @@ -1,8 +1,10 @@ <?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"> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:x="http://www.w3.org/1999/xhtml" exclude-result-prefixes="x" xmlns="http://www.w3.org/1999/xhtml"> - <xsl:output doctype-system="../../dtd/ThML10.dtd"/> + <xsl:output method="xhtml"/> + + <xsl:template match="x:p[not(text())]"/><!-- These mess up the count later --> <xsl:template match="node()|@*"> <xsl:copy> @@ -10,62 +12,22 @@ </xsl:copy> </xsl:template> - <!-- Next three should not be necessary, but the -expand:off switch doesn't seem to be working in Saxon 9 --> - <xsl:template match="p/@shownumber[.='no']"/> - - <xsl:template match="a/@shape[.='rect']"/> - - <xsl:template match="a/@xml:link[.='simple']"/> <!-- ! bogus, but hard to fix --> - - <xsl:template match="div4[not(div/*[@xml:lang='la']) - and div/p[@xml:lang='en' - and not(b)]]"> - <!-- Try to detect cases where a single sub-part (typically the respondeo) is spread over multiple paras, and merge them. Don't mess with anything that -has latin already --> - <xsl:copy> - <xsl:apply-templates select="@*|h4"/> - <xsl:for-each-group select="div/p" group-starting-with="p[*[1][self::b]]"> - <!--<xsl:message><xsl:value-of select="../../@id"/>: <xsl:value-of select="position()"/>,<xsl:value-of select="count(current-group())"/></xsl:message>--> - <xsl:text> </xsl:text> - <div class="bilingual"> - <xsl:text> </xsl:text> - <xsl:choose> - <xsl:when test="current-group()[2]"> - <div xml:lang="en"> - <xsl:text> </xsl:text> - <xsl:apply-templates select="current-group()"/> - <xsl:text> </xsl:text> - </div> - </xsl:when> - <xsl:otherwise> - <xsl:apply-templates select="current-group()"/> - </xsl:otherwise> - </xsl:choose> - <xsl:text> </xsl:text> - </div> - </xsl:for-each-group> - <xsl:text> </xsl:text> - </xsl:copy> - </xsl:template> - - <xsl:template match="div3[div[2]]"> - <!-- Try to detect the splayed out questions at the beginning of each Question --> + <xsl:template match="x:div[@class='div3']"> + <!-- Doc elt. + Collect the splayed out questions at the beginning of each Question + (Loses some empty <a...> at the beginning --> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:text> </xsl:text> - <xsl:apply-templates select="h3"/> + <xsl:apply-templates select="x:h3"/> <xsl:text> </xsl:text> - <div class="bilingual"> + <div class="div4"> <xsl:text> </xsl:text> - <div xml:lang="en"> - <xsl:text> </xsl:text> - <xsl:apply-templates select="div/p"/> - <xsl:text> </xsl:text> - </div> + <xsl:apply-templates select="x:p"/> <xsl:text> </xsl:text> </div> <xsl:text> </xsl:text> - <xsl:apply-templates select="div4"/> + <xsl:apply-templates select="x:div"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/summa/bilingual/merge.xpl Tue Dec 29 18:40:48 2009 +0000 @@ -0,0 +1,16 @@ +<?xml version='1.0'?> +<!DOCTYPE p:pipeline SYSTEM "../../../../WWW/XML/XProc/docs/schemas/xproc.dtd" > +<p:pipeline xmlns:p="http://www.w3.org/ns/xproc" xmlns="http://www.w3.org/1999/xhtml"> + <p:viewport match="div[@class='div3']"> + <p:xslt> + <p:input port="stylesheet"> + <p:document href="fixup_e.xsl"/> + </p:input> + </p:xslt> + <p:xslt> + <p:input port="stylesheet"> + <p:document href="merge.xsl"/> + </p:input> + </p:xslt> + </p:viewport> +</p:pipeline>
--- a/summa/bilingual/merge.xsl Mon Dec 28 13:00:58 2009 +0000 +++ b/summa/bilingual/merge.xsl Tue Dec 29 18:40:48 2009 +0000 @@ -1,6 +1,6 @@ <?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"> +<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 --> @@ -17,40 +17,81 @@ </xsl:copy> </xsl:template> - <xsl:template match="/x:div/x:div[not(@n)]"> + <xsl:template match="x:div[@class='div4' and not(@id)]"> <!-- Wrap a prooemium --> <xsl:copy> - <xsl:apply-templates select="@*|node()"/> - <xsl:apply-templates select="$la/x:div[@class='p']/x:p"/> + <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/x:div[@n]"> + <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[@n])+1"/> + <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:message><xsl:value-of select="@n"/>,<xsl:value-of select="$n"/>,<xsl:value-of select="@title"/>,<xsl:value-of select="count(x:div)"/>,<xsl:value-of select="$ld/x:h3"/>,<xsl:value-of select="count($ld/x:p)"/></xsl:message> + <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> <xsl:choose> - <xsl:when test="count(x:div)=count($ld/x:p)"> + <xsl:when test="count(x:p)=count($ld/x:p)"> <xsl:copy> <xsl:apply-templates select="@*|x:h4"/> - <xsl:for-each select="x:div"> + <xsl:for-each select="x:p"> <xsl:variable name="i" select="position()"/> - <xsl:copy> - <xsl:apply-templates select="@*|x:div[1]"/> - <xsl:for-each select="x:div[2]"> - <xsl:copy> - <xsl:apply-templates select="@*"/> - <xsl:apply-templates select="$ld/x:p[position()=$i]"/> - </xsl:copy> - </xsl:for-each> - </xsl:copy> + <xsl:call-template name="doBi"> + <xsl:with-param select="." name="english"/> + <xsl:with-param select="$ld/x:p[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="@n"/>, <xsl:value-of select="count(x:div)"/>!=<xsl:value-of select="count($ld/x:p)"/></xsl:message> + <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> + <!-- 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($ld/x:p)"> + <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="$ld/x:p[position()=$i]" name="latin"/> + </xsl:call-template> + </xsl:for-each-group> + </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($ld/x:p)"/></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>
