Skip to content

Commit

Permalink
Fix docbook#97 by making sure CALS table row and entry xml:ids become…
Browse files Browse the repository at this point in the history
… id attributes
  • Loading branch information
ndw committed May 9, 2021
1 parent c18d0bf commit 79e5599
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 3 deletions.
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,6 @@ fileTree(dir: "${projectDir}/src/test/resources/xml", include: "*.xml").each { x
stylesheetParams['mediaobject-output-base-uri'] = "media/"
stylesheetParams['dynamic-profiles'] = true

//println("Task ${base}.expected: ${stylesheetParams}")

input xml
stylesheet "${buildDir}/xslt/xspec-driver.xsl"
output "${projectDir}/src/test/resources/expected/${base}.html"
Expand Down Expand Up @@ -1702,7 +1700,7 @@ publishing {
task helloWorld() {
doLast {
println('Hello, world: ' + xslTNGversion)
project.objects.fileCollection().each { path ->
configurations.validateRuntime.each { path ->
println("CP: ${path}")
}

Expand Down
8 changes: 8 additions & 0 deletions src/main/xslt/modules/attributes.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@
(local-name(.), $pgwide, $landscape, $style), ())"/>
</xsl:template>

<xsl:template match="db:row"
mode="m:attributes" as="attribute()*">
<xsl:variable name="attr" as="attribute()*">
<xsl:apply-templates select="@*"/>
</xsl:variable>
<xsl:sequence select="f:attributes(., $attr, (), ())"/>
</xsl:template>

<xsl:template match="db:imagedata|db:videodata|db:audiodata"
mode="m:attributes" as="attribute()*">
<xsl:variable name="attr" as="attribute()*">
Expand Down
8 changes: 8 additions & 0 deletions src/main/xslt/modules/tablecals.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<xsl:message use-when="'tables' = $debug"
select="'========================================'"/>
<tr>
<xsl:apply-templates select="." mode="m:attributes"/>
<xsl:for-each select="1 to fcals:table-columns($row)">
<xsl:variable name="cell" select="fcals:cell($row, ., $overhang, $cells)"/>
<xsl:choose>
Expand Down Expand Up @@ -292,6 +293,13 @@
</xsl:variable>

<xsl:element name="{$td}" namespace="http://www.w3.org/1999/xhtml">
<!-- Can't (easily) use the m:attributes mode here because we need
to output the appropriate attributes even when there is no
DocBook node. (For example, when a cell is omitted.) -->
<xsl:if test="map:contains($properties, 'node')
and $properties?node/@xml:id">
<xsl:attribute name="id" select="$properties?node/@xml:id"/>
</xsl:if>
<xsl:if test="exists($classes)">
<xsl:variable name="sorted" as="xs:string+">
<xsl:for-each select="$classes">
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/expected/table-cals.050.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" class="no-js"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>CALS table with IDs</title><meta name="viewport" content="width=device-width, initial-scale=1.0"/><link href="http://purl.org/dc/elements/1.1/" rel="schema.dc"/><meta content="2011-04-22T17:02:00-06:00" name="dc.modified"/><meta content="DocBook xslTNG" name="generator"/><link href="./css/docbook.css" rel="stylesheet"/><link href="./css/docbook-screen.css" rel="stylesheet"/></head><body class="home"><nav class="top"></nav><main><article class="article"><header><h1>CALS table with IDs</h1></header><p>Tests that IDs appear on the resulting HTML table.</p><figure id="inftable" class="informaltable"><table><thead id="thead1"><tr id="thead1r1"><th id="thead1r1c1" class="bleft btop colsep rowsep">Left</th><th id="thead1r1c2" class="btop colsep rowsep">Middle</th><th id="thead1r1c3" class="btop colsep rowsep">Right</th></tr></thead><tfoot id="tfoot1"><tr id="tfoot1r1"><td id="tfoot1r1c1" class="bleft btop colsep rowsep">Left</td><td class="btop colsep empty rowsep"></td><td id="tfoot1r1c3" class="btop colsep rowsep">Right</td></tr></tfoot><tbody id="tbody1"><tr id="tbody1r1"><td id="tbody1r1c1" class="bleft btop colsep rowsep"></td><td id="tbody1r1c2" class="btop colsep rowsep">·</td><td id="tbody1r1c3" class="btop colsep rowsep"></td></tr><tr><td id="tbody1r2c1" class="bleft colsep rowsep"></td><td class="colsep rowsep">·</td><td id="tbody1r2c3" class="colsep rowsep"></td></tr></tbody></table></figure></article></main><nav class="bottom"></nav></body></html>
39 changes: 39 additions & 0 deletions src/test/resources/xml/table-cals.050.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<article xmlns="http://docbook.org/ns/docbook" version="5.0">
<title>CALS table with IDs</title>
<para>Tests that IDs appear on the resulting HTML table.</para>

<informaltable frame="all" xml:id="inftable">
<tgroup cols="3" colsep="1" rowsep="1" xml:id="tgroup1">
<colspec colname="c1"/>
<colspec colname="c2"/>
<colspec colname="c3"/>
<thead xml:id="thead1">
<row xml:id="thead1r1">
<entry xml:id="thead1r1c1">Left</entry>
<entry xml:id="thead1r1c2">Middle</entry>
<entry xml:id="thead1r1c3">Right</entry>
</row>
</thead>
<tfoot xml:id="tfoot1">
<row xml:id="tfoot1r1">
<entry xml:id="tfoot1r1c1">Left</entry>
<entry namest="c3" xml:id="tfoot1r1c3">Right</entry>
</row>
</tfoot>
<tbody xml:id="tbody1">
<row xml:id="tbody1r1">
<entry xml:id="tbody1r1c1">←</entry>
<entry xml:id="tbody1r1c2">·</entry>
<entry xml:id="tbody1r1c3">→</entry>
</row>
<row>
<entry xml:id="tbody1r2c1">←</entry>
<entry>·</entry>
<entry xml:id="tbody1r2c3">→</entry>
</row>
</tbody>
</tgroup>

</informaltable>
</article>
5 changes: 5 additions & 0 deletions src/test/xspec/tablecals.xspec
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,9 @@
<x:context href="../resources/xml/table-cals.049.xml"/>
<x:expect label="expect very large tables to succeed" href="../resources/expected/table-cals.049.html"/>
</x:scenario>

<x:scenario label="When transforming table-cals.050.xml">
<x:context href="../resources/xml/table-cals.050.xml"/>
<x:expect label="expect row/entry xml:ids to become id attributes" href="../resources/expected/table-cals.050.html"/>
</x:scenario>
</x:description>

0 comments on commit 79e5599

Please sign in to comment.