Skip to content

Commit

Permalink
Make spanning aligned text work for the first element(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhellingman committed Sep 17, 2024
1 parent 39dc49b commit 1318015
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 28 deletions.
87 changes: 63 additions & 24 deletions modules/divisions.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -841,33 +841,72 @@
<xsl:param name="secondLang" as="xs:string?"/>
<xsl:param name="anchors" as="xs:string*"/>

<xsl:if test="($first or $second) and (not($first/@n = $anchors) or not($second/@n = $anchors))">
<tr>
<td class="first">
<xsl:copy-of select="f:generate-lang-attribute($firstLang)"/>
<xsl:choose>

<xsl:if test="$first and not($first/@n = $anchors)">
<xsl:apply-templates select="$first"/>
<xsl:call-template name="output-inserted-paragraphs">
<xsl:with-param name="start" select="$first"/>
<xsl:with-param name="anchors" select="$anchors"/>
</xsl:call-template>
</xsl:if>
</td>
<xsl:when test="f:rend-value($first/@rend, 'span-alignment') = 'both'">
<tr>
<td colspan="2">
<xsl:copy-of select="f:generate-lang-attribute($firstLang)"/>

<td class="second">
<xsl:copy-of select="f:generate-lang-attribute($secondLang)"/>
<xsl:if test="$first and not($first/@n = $anchors)">
<xsl:apply-templates select="$first"/>
<xsl:call-template name="output-inserted-paragraphs">
<xsl:with-param name="start" select="$first"/>
<xsl:with-param name="anchors" select="$anchors"/>
</xsl:call-template>
</xsl:if>

<xsl:if test="$second and not($second/@n = $anchors)">
<xsl:apply-templates select="$second"/>
<xsl:call-template name="output-inserted-paragraphs">
<xsl:with-param name="start" select="$second"/>
<xsl:with-param name="anchors" select="$anchors"/>
</xsl:call-template>
</xsl:if>
</td>
</tr>
</xsl:if>
<xsl:copy-of select="f:log-warning('Left-side paragraph {1} will span both columns; matching right-side column will be skipped.', ($first/@n))"/>
</td>
</tr>
</xsl:when>

<xsl:when test="f:rend-value($second/@rend, 'span-alignment') = 'both'">
<tr>
<td colspan="2">
<xsl:copy-of select="f:generate-lang-attribute($secondLang)"/>

<xsl:if test="$second and not($second/@n = $anchors)">
<xsl:apply-templates select="$second"/>
<xsl:call-template name="output-inserted-paragraphs">
<xsl:with-param name="start" select="$second"/>
<xsl:with-param name="anchors" select="$anchors"/>
</xsl:call-template>
</xsl:if>

<xsl:copy-of select="f:log-warning('Right-side paragraph {1} will span both columns; matching left-side column will be skipped.', ($second/@n))"/>
</td>
</tr>
</xsl:when>

<xsl:when test="($first or $second) and (not($first/@n = $anchors) or not($second/@n = $anchors))">
<tr>
<td class="first">
<xsl:copy-of select="f:generate-lang-attribute($firstLang)"/>

<xsl:if test="$first and not($first/@n = $anchors)">
<xsl:apply-templates select="$first"/>
<xsl:call-template name="output-inserted-paragraphs">
<xsl:with-param name="start" select="$first"/>
<xsl:with-param name="anchors" select="$anchors"/>
</xsl:call-template>
</xsl:if>
</td>

<td class="second">
<xsl:copy-of select="f:generate-lang-attribute($secondLang)"/>

<xsl:if test="$second and not($second/@n = $anchors)">
<xsl:apply-templates select="$second"/>
<xsl:call-template name="output-inserted-paragraphs">
<xsl:with-param name="start" select="$second"/>
<xsl:with-param name="anchors" select="$anchors"/>
</xsl:call-template>
</xsl:if>
</td>
</tr>
</xsl:when>
</xsl:choose>
</xsl:template>


Expand Down
8 changes: 4 additions & 4 deletions modules/drama.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
<xsl:choose>
<xsl:when test="not(f:should-display-lg(.))"/>
<xsl:when test="f:has-rend-value(@rend, 'align-with')">
<xsl:call-template name="handleAlignedLg"/>
<xsl:call-template name="handle-align-lg"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="handleLg"/>
<xsl:call-template name="handle-lg"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Expand Down Expand Up @@ -141,7 +141,7 @@
on the screen, and still keep the left side of all stanzas aligned.</xd:detail>
</xd:doc>

<xsl:template name="handleLg">
<xsl:template name="handle-lg">
<xsl:context-item as="element(lg)" use="required"/>

<xsl:call-template name="closepar"/>
Expand All @@ -164,7 +164,7 @@
<xd:detail>Format two aligned lg elements: determine which two verses need to be aligned.</xd:detail>
</xd:doc>

<xsl:template name="handleAlignedLg">
<xsl:template name="handle-align-lg">
<xsl:context-item as="element(lg)" use="required"/>
<xsl:variable name="otherId" select="f:rend-value(@rend, 'align-with')"/>
<xsl:copy-of select="f:log-info('Align verse {1} with verse {2}.', (@id, $otherId))"/>
Expand Down
63 changes: 63 additions & 0 deletions xspec/divisions.xspec
Original file line number Diff line number Diff line change
Expand Up @@ -720,4 +720,67 @@
</x:scenario>


<x:scenario label="When rendering a text with a body and two div1 elements, which should be aligned side-by-side, and a paragraph that should span both columns of the alignment">
<x:context select="//text">
<TEI>
<text>
<body>
<div1 id="d1" rend="align-with(d2)">
<head rend="span-alignment(both)">Spanned Division 1</head>
<p n="1">Paragraph 1.1</p>
<p n="2">Paragraph 1.2</p>
<p n="3">Paragraph 1.3</p>

</div1>
<div1 id="d2" rend="display(none)">
<head>Skipped Division 2</head>
<p n="1">Paragraph 2.1</p>
<p n="2">Paragraph 2.2</p>
<p n="3">Paragraph 2.3</p>
</div1>
</body>
</text>
</TEI>
</x:context>
<x:expect label="will result in an HTML table with the aligned content side-by-side and one paragraph spanning both columns">
<div xmlns="http://www.w3.org/1999/xhtml" class="body" id="...">
<div id="d1" class="div1">
<a id="d2"/>
<table class="alignedText">
<tr>
<td colspan="2">
<h2 id="..." class="main">Spanned Division 1</h2>
</td>
</tr>
<tr>
<td class="first">
<p id="..." class="first">Paragraph 1.1</p>
</td>
<td class="second">
<p id="..." class="first">Paragraph 2.1</p>
</td>
</tr>
<tr>
<td class="first">
<p id="...">Paragraph 1.2</p>
</td>
<td class="second">
<p id="...">Paragraph 2.2</p>
</td>
</tr>
<tr>
<td class="first">
<p id="...">Paragraph 1.3</p>
</td>
<td class="second">
<p id="...">Paragraph 2.3</p>
</td>
</tr>
</table>
</div>
</div>
</x:expect>
</x:scenario>


</x:description>

0 comments on commit 1318015

Please sign in to comment.