Skip to content

Commit

Permalink
Merge pull request #139 from metanorma/table_autolayout_child
Browse files Browse the repository at this point in the history
Table autolayout child
  • Loading branch information
Intelligent2013 authored Sep 3, 2022
2 parents 7abecb7 + 2183562 commit 6597389
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions src/main/resources/tables_only.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,80 @@

<xsl:template match="*[local-name() = 'fn']"/>

<xsl:template match="*[local-name() = 'table' or local-name() = 'dl']">
<xsl:choose>
<xsl:when test="ancestor::*[local-name() = 'table' or local-name() = 'dl']"> <!-- if there is parent table / definition list -->


<xsl:choose>
<xsl:when test="local-name() = 'table'">

<xsl:for-each select=".//*[local-name() = 'tr']">
<xsl:variable name="ns" select="namespace-uri()"/>
<xsl:element name="p" namespace="{$ns}">
<xsl:for-each select=".//*[local-name() = 'td']">
<xsl:apply-templates mode="simple_td"/>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:element>
</xsl:for-each>

</xsl:when> <!-- table -->

<xsl:when test="local-name() = 'dl'">

<!-- convert definition list to paragraphs -->
<xsl:for-each select=".//*[local-name() = 'dt']">
<xsl:variable name="ns" select="namespace-uri()"/>
<xsl:element name="p" namespace="{$ns}">
<xsl:copy-of select="node()"/>
<xsl:text> </xsl:text>
<xsl:apply-templates select="following-sibling::*[local-name()='dd'][1]/*[local-name() = 'p']/node()" />
</xsl:element>
</xsl:for-each>
</xsl:when> <!-- dl -->

</xsl:choose>
</xsl:when>
<xsl:otherwise> <!-- table/dl doesn't have parent tables / definition lists, i.e. most upper element -->

<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>

<!-- put child tables / definition lists after table -->

<!-- isolate child table and dl from parent table context -->
<xsl:variable name="table_dl_id" select="@id"/>
<xsl:variable name="child_tables_dl">
<xsl:for-each select=".//*[local-name() = 'table' or local-name() = 'dl'][ancestor::*[local-name() = 'table' or local-name() = 'dl'][1][@id = $table_dl_id]]">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:variable>
<!-- <iter> -->
<xsl:apply-templates select="xalan:nodeset($child_tables_dl)/*" />
<!-- </iter> -->
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<xsl:template match="@*|node()" mode="simple_td">
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="simple_td"/>
</xsl:copy>
</xsl:template>

<xsl:template match="*[local-name() = 'dl']" mode="simple_td">
<!-- convert definition list to paragraphs -->
<xsl:for-each select=".//*[local-name() = 'dt']">
<xsl:variable name="ns" select="namespace-uri()"/>
<xsl:element name="p" namespace="{$ns}">
<xsl:copy-of select="node()"/>
<xsl:text> </xsl:text>
<xsl:apply-templates select="following-sibling::*[local-name()='dd'][1]/*[local-name() = 'p']/node()" mode="simple_td"/>
</xsl:element>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

0 comments on commit 6597389

Please sign in to comment.