Skip to content

Commit b1eb353

Browse files
committed
copy cell properties from table styles
1 parent 32562f8 commit b1eb353

File tree

1 file changed

+53
-12
lines changed

1 file changed

+53
-12
lines changed

src/main/ml-modules/root/judgments/xslts/accessible-html.xsl

+53-12
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,20 @@
331331
<xsl:sequence select="key('class-properties', $key, $all-classes-parsed)/string()" />
332332
</xsl:function>
333333

334+
<!-- returns a sequence of key/value pairs, each divided by a colon -->
335+
<xsl:function name="uk:get-all-class-properties" as="xs:string*">
336+
<xsl:param name="context" as="element()" />
337+
<xsl:param name="selector" as="xs:string" /> <!-- constructed with helper function below -->
338+
<xsl:variable name="key" select="concat(generate-id($context), '|', $selector)" />
339+
<xsl:for-each select="key('classes', $key, $all-classes-parsed)/uk:property">
340+
<xsl:sequence select="concat(@key, ':', @value)" />
341+
</xsl:for-each>
342+
</xsl:function>
343+
334344
<!-- returns a sequence of key/value pairs, each divided by a colon -->
335345
<xsl:function name="uk:get-inline-class-properties-1" as="xs:string*">
336346
<xsl:param name="context" as="element()" />
337-
<xsl:param name="selector" as="xs:string" />
347+
<xsl:param name="selector" as="xs:string" /> <!-- constructed with helper function below -->
338348
<xsl:variable name="key" select="concat(generate-id($context), '|', $selector)" />
339349
<xsl:for-each select="key('classes', $key, $all-classes-parsed)/uk:property">
340350
<xsl:if test="string(@key) = $inline-properties">
@@ -345,29 +355,40 @@
345355

346356
<!-- helper functions to make selectors, depending on context -->
347357

348-
<xsl:function name="uk:make-class-selector" as="xs:string?">
358+
<!-- adds a prefix to class selector, e.g., #judgment, #main, etc., depending on context -->
359+
<xsl:function name="uk:augment-simple-class-selector" as="xs:string">
349360
<xsl:param name="context" as="element()" />
350-
<xsl:param name="e" as="element()" />
361+
<xsl:param name="class" as="xs:string" /> <!-- starts with a dot -->
351362
<xsl:choose>
352-
<xsl:when test="empty($e/@class)" />
353-
<xsl:when test="$doc-id = 'ewhc/ch/2022/1178'">
354-
<xsl:sequence select="uk:make-class-selector-for-ewhc-ch-2022-1178($context, $e)" />
355-
</xsl:when>
356363
<!-- the selector for main styles in a judgment is '#judgment .{ClassName}', e.g., '#judgment .ParaLevel1' -->
357364
<xsl:when test="$context/self::judgment">
358-
<xsl:sequence select="concat('#judgment .', $e/@class)" />
365+
<xsl:sequence select="concat('#judgment ', $class)" />
359366
</xsl:when>
360367
<!-- the selector for main styles in a press summary is '#main .{ClassName}', e.g., '#main .ParaLevel1' -->
361368
<xsl:when test="$context/self::doc[@name='pressSummary']">
362-
<xsl:sequence select="concat('#main .', $e/@class)" />
369+
<xsl:sequence select="concat('#main ', $class)" />
363370
</xsl:when>
364371
<!-- the selector for attachment styles is '#{type}{num} .{ClassName}', e.g., '#order1 .ParaLevel1' -->
365372
<xsl:otherwise>
366373
<xsl:variable name="work-uri" as="xs:string" select="$context/meta/identification/FRBRWork/FRBRthis/@value" />
367374
<xsl:variable name="uri-components" as="xs:string*" select="tokenize($work-uri, '/')" />
368375
<xsl:variable name="last-two" as="xs:string*" select="$uri-components[position() >= last()-1]" />
369376
<xsl:variable name="last-two-combined" as="xs:string" select="string-join($last-two, '')" />
370-
<xsl:sequence select="concat('#', $last-two-combined, ' .', $e/@class)" />
377+
<xsl:sequence select="concat('#', $last-two-combined, ' ', $class)" />
378+
</xsl:otherwise>
379+
</xsl:choose>
380+
</xsl:function>
381+
382+
<xsl:function name="uk:make-class-selector" as="xs:string?">
383+
<xsl:param name="context" as="element()" />
384+
<xsl:param name="e" as="element()" />
385+
<xsl:choose>
386+
<xsl:when test="empty($e/@class)" />
387+
<xsl:when test="$doc-id = 'ewhc/ch/2022/1178'">
388+
<xsl:sequence select="uk:make-class-selector-for-ewhc-ch-2022-1178($context, $e)" />
389+
</xsl:when>
390+
<xsl:otherwise>
391+
<xsl:sequence select="uk:augment-simple-class-selector($context, concat('.', $e/@class))" />
371392
</xsl:otherwise>
372393
</xsl:choose>
373394
</xsl:function>
@@ -743,18 +764,38 @@
743764
<xsl:variable name="header-rows" as="element()*" select="*[child::th]" />
744765
<xsl:if test="exists($header-rows)">
745766
<thead>
746-
<xsl:apply-templates select="$header-rows" />
767+
<xsl:apply-templates select="$header-rows">
768+
<xsl:with-param name="table-class" as="xs:string?" select="@class" tunnel="yes" />
769+
</xsl:apply-templates>
747770
</thead>
748771
</xsl:if>
749772
<tbody>
750-
<xsl:apply-templates select="* except $header-rows" />
773+
<xsl:apply-templates select="* except $header-rows">
774+
<xsl:with-param name="table-class" as="xs:string?" select="@class" tunnel="yes" />
775+
</xsl:apply-templates>
751776
</tbody>
752777
</table>
753778
</xsl:template>
754779

755780
<xsl:template match="tr | th | td">
781+
<xsl:param name="class-context" as="element()" tunnel="yes" />
782+
<xsl:param name="table-class" as="xs:string?" tunnel="yes" />
756783
<xsl:element name="{ local-name() }">
757784
<xsl:copy-of select="@*" />
785+
<xsl:if test="$table-class">
786+
<xsl:variable name="selector" as="xs:string" select="concat('.', $table-class, ' ', local-name(.))" /> <!-- e.g., '.TableClass1 td' -->
787+
<xsl:variable name="selector" as="xs:string" select="uk:augment-simple-class-selector($class-context, $selector)" /> <!-- e.g., '#judgment .TableClass1 td' -->
788+
<xsl:variable name="table-class-properties" select="uk:get-all-class-properties($class-context, $selector)" />
789+
<xsl:if test="exists($table-class-properties)">
790+
<xsl:attribute name="style">
791+
<xsl:value-of select="string-join($table-class-properties, ';')" />
792+
<xsl:if test="exists(@style)">
793+
<xsl:value-of select="';'" />
794+
<xsl:value-of select="concat(';', @style)" />
795+
</xsl:if>
796+
</xsl:attribute>
797+
</xsl:if>
798+
</xsl:if>
758799
<xsl:apply-templates />
759800
</xsl:element>
760801
</xsl:template>

0 commit comments

Comments
 (0)